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

multipdf.PDFMergerUtility error handling large documents

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Problem
    • Affects Version/s: 2.0.6
    • Fix Version/s: None
    • Component/s: Utilities
    • Labels:
      None

      Description

      org.apache.pdfbox.multipdf.PDFMergerUtility are having problems merging large documents.

      I have folowing method and testcase:

      public static File mergePdfFiles(List<File> files, File outputFile) throws IOException {
      		PDFMergerUtility merger = new PDFMergerUtility();
      		merger.setDestinationStream(new FileOutputStream(outputFile));
      		for (Iterator<File> fileIt = files.iterator(); fileIt.hasNext();) {
      			merger.addSource(fileIt.next().getAbsolutePath());
      		}
      		merger.mergeDocuments(MemoryUsageSetting.setupMixed(30000000));
      		//		merger.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
      		//		merger.mergeDocuments(MemoryUsageSetting.setupTempFileOnly());
      		return outputFile;
      	}
      
      @Test
      	public void test() {
      		File outputFile;
      		try {
      			outputFile = File.createTempFile("PDFMergerTest", ".pdf");
      
      			List<File> files = new ArrayList<File>();
      			files.add(new File("src/test/resources/06.pdf"));
      			files.add(new File("src/test/resources/062.pdf"));
      			int totalPageCount = 0;
      			for (File file : files) {
      				totalPageCount += PDFUtil.countPages(file);
      			}
      			PDFMerger.mergePdfFiles(files, outputFile);
      			assertEquals("Page numbers match", totalPageCount, PDFUtil.countPages(outputFile));
      		} catch (IOException e1) {
      			// TODO Auto-generated catch block
      			e1.printStackTrace();
      		}
      	}
      

      This does for all three MemoryUsageSetting "setupMainMemoryOnly(), setupTempFileOnly(), setupMixed(30000000)" return the the following error:

      -------------------------------------------------------
      T E S T S
      -------------------------------------------------------
      Running dk.dataproces.utilities.pdf.test.PDFMergerTest
      Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.223 sec <<< FAILURE!
      test(dk.dataproces.utilities.pdf.test.PDFMergerTest) Time elapsed: 1.179 sec <<< ERROR!
      java.lang.StackOverflowError
      at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:76)
      at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:108)
      at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:136)
      at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:99)
      at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:136)
      at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:99)
      at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:136)
      at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:99)
      at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:136)
      at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:99)
      at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:136)
      at org.apache.pdfbox.multipdf.PDFCloneUtility.cloneForNewDocument(PDFCloneUtility.java:99)
      ....................................AND THIS GOES ON FOR LONG IN THE CONSOLE

        Attachments

        1. 06.pdf
          5.00 MB
          Jens Henrik Rauff Hansen
        2. 062.pdf
          5.00 MB
          Jens Henrik Rauff Hansen

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              rauff Jens Henrik Rauff Hansen
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: