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

After flattening a form pdf, the pdf loses content

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 3.0.3 PDFBox
    • None
    • AcroForm
    • None
    • Mac Ventura, java 18 PDFBox 3.0.3, Tomcat 9
      Linux; version: 5.15.0-105-generic, java 17, Tomcat 9.0.93

    Description

      After flattening the pdf form content changes. Pls take a look at before and after pdf. The flattening works fine in 2.0.31. After upgrading to 3.0.3 we started getting many issues with pdf forms after flattening. 
      The code that used for flattening is as follows

      PDDocument pdDocument = Loader.loadPDF(file, “”);
      pdDocument.setResourceCache(new PdfResourceCache())
      try {
          boolean save = false;
          if (pdDocument.isEncrypted()) {      
              pdDocument.setAllSecurityToBeRemoved(true);
              save = true;
          }
          final PDDocumentCatalog pdDocumentCatalog = pdDocument.getDocumentCatalog();
          if (pdDocumentCatalog != null) {
              final PDAcroForm pdForm = pdDocumentCatalog.getAcroForm();
              if (pdForm != null) {       
                  pdForm.flatten();         
                  save = true;
              }
          }
          if (save) {
              pdDocument.save(file);        
          }
      }
      

      Attachments

        1. beforeFalttening.pdf
          116 kB
          Joseph Jezerinac
        2. flattenedPdf.pdf
          31 kB
          Joseph Jezerinac

        Activity

          People

            Unassigned Unassigned
            jezerinac Joseph Jezerinac
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: