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

Merge failed to clone tags

    XMLWordPrintableJSON

Details

    • Patch

    Description

      After merging two tagged documents, closing the source document causes the destination document to be closed, which prevents it from being saved. The following code demonstrates the bug with the attached flattened government PDF file. The original is available here if you need it.

      @Test
      public void testMerge() throws Exception {
          PDFMergerUtility pdfMergerUtility = new PDFMergerUtility();
          PDDocument src = PDDocument.load(new File("GovFormPreFlattened.pdf"));
          PDDocument dest = PDDocument.load(new File("GovFormPreFlattened.pdf"));
          pdfMergerUtility.appendDocument(dest, src);
          src.close(); //if we don't close the src then we don't have an error
          dest.save(File.createTempFile("MergeIssue",".PDF"));
          dest.close();
      }
      

      The issue is resolved with the attached patch.

      Also I removed the "if (mergeStructTree)" is because mergeStructTree is always true here because this code is already inside an "if (mergeStructTree)".

      Attachments

        1. GeneralForbearance.pdf
          660 kB
          Tilman Hausherr
        2. pdfbox.patch
          2 kB
          Dave Hill
        3. GovFormPreFlattened.pdf
          622 kB
          Dave Hill

        Issue Links

          Activity

            People

              tilman Tilman Hausherr
              DavesPlanet Dave Hill
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: