You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Ulf Ballach <ub...@opentext.com.INVALID> on 2023/02/23 13:24:59 UTC

OOM when merging large files

Hi,

I am trying to merge two large PDF files into one using the PDFMergerUtility like so:

public static void main(String[] args) throws Exception {
      final PDFMergerUtility merger = new PDFMergerUtility();
      merger.addSource("input1.pdf");
merger.addSource("input2.pdf");
      merger.setDestinationFileName("output.pdf");
      merger.setDocumentMergeMode(DocumentMergeMode.OPTIMIZE_RESOURCES_MODE);
      merger.mergeDocuments(MemoryUsageSetting.setupTempFileOnly());
}

The input files for the example are about 600MB in size, have 8000 pages which each contain a large image that spans almost the entire page and a small bit of text at the top. I can provide the test files but I think that the exact content of the file is probably not important.

This code runs in a process with only 512MB of Memory and throws a OutOfMemoryError on the mergeDocuments() call. The DocumentMergeMode and MemoryUsageSetting options did not really help me. Is there something I can do to significantly reduce the memory footprint? All I want to do is concatenate multiple PDFs into one (and possibly add an outline afterwards if that worked) and thought that the PDFMergerUtility would be the most efficient way to do that.

Thanks,
Ulf Ballach