PDF File Operations
PdfFileEditor
PdfFileEditor provides methods for high-level PDF file manipulation: concatenating
documents, extracting page subsets, splitting into individual pages, and inserting pages.
PdfFileEditor editor = new PdfFileEditor();
editor.concatenate("first.pdf", "second.pdf", "merged.pdf");
editor.extract("source.pdf", 2, 5, "pages2to5.pdf");
editor.splitToPages("document.pdf", "output/");Content Resizing
Use ContentsResizeParameters with ContentsResizeValue to scale page content
within existing page boundaries. The six-argument constructor takes values in order:
leftMargin, contentsWidth, rightMargin, topMargin, contentsHeight, bottomMargin.
ContentsResizeParameters params = new ContentsResizeParameters(
ContentsResizeValue.percents(5),
ContentsResizeValue.percents(90),
ContentsResizeValue.percents(5),
ContentsResizeValue.percents(5),
ContentsResizeValue.percents(90),
ContentsResizeValue.percents(5)
);
PdfFileEditor editor = new PdfFileEditor();
editor.resizeContents(doc, params);Large File Handling
For large documents, enable disk buffering to avoid heap exhaustion:
PdfFileEditor editor = new PdfFileEditor();
editor.setUseDiskBuffer(true);
editor.concatenate(inputFiles, "output.pdf");Related APIs
See also: PdfPageEditor, ContentsResizeParameters, Document.