Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-4636

"There has been a widget with a missing page reference" and non widget annotation gets flattened

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.16
    • 2.0.17, 3.0.0 PDFBox
    • AcroForm
    • None

    Description

      I get this when attempting to flatten the attached file (which is an "improved" version of the file from the linked issue)

      26.08.2019 18:41:00.354 WARN [main] org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm:853 - There has been a widget with a missing page reference. Please report to the PDFBox project

       The intention is to "preserve all non widget annotations". This code reproduces the problem:

      PDDocument doc = PDDocument.load(new File("PDFBOX-4636.pdf"));
      List<PDAnnotation> annotations = doc.getPage(0).getAnnotations();
      PDColor red = new PDColor(new float[] { 1, 0, 0 }, PDDeviceRGB.INSTANCE);
      PDColor blue = new PDColor(new float[] { 0, 0, 1 }, PDDeviceRGB.INSTANCE);
      PDAnnotationCircle circleAnnotation = new PDAnnotationCircle();
      circleAnnotation.setContents("Circle Annotation");
      circleAnnotation.setInteriorColor(red);
      circleAnnotation.setColor(blue);
      circleAnnotation.setRectangle(new PDRectangle(100, 700, 100, 50));
      circleAnnotation.setPage(doc.getPage(0));
      circleAnnotation.constructAppearances();
      annotations.add(circleAnnotation);
      doc.save("PDFBOX-4636-annotated.pdf");
      
      doc.getDocumentCatalog().getAcroForm().flatten();
      doc.save("PDFBOX-4636-flattened-bad.pdf");
      doc.close();
      
      doc = PDDocument.load(new File("PDFBOX-4636-annotatedAP.pdf")); // PDFBOX-4636-annotated.pdf opened with Adobe and saved
      doc.getDocumentCatalog().getAcroForm().flatten();
      doc.save("PDFBOX-4636-flattened-good.pdf");
      doc.close();
      

      what should have happened: result file PDFBOX-4636-flattened-good.pdf has 1 annotation.

      what happened instead: result file has PDFBOX-4636-flattened-bad.pdf no annotation, because the circle annotation has been flattened as well.

      Attachments

        1. PDFBOX-4636.pdf
          913 kB
          Tilman Hausherr

        Issue Links

          Activity

            People

              tilman Tilman Hausherr
              tilman Tilman Hausherr
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: