Skip to main content

Combine PDF in Java

Combine PDF in Java

How to Combine PDFs​

Combining PDFs together with DynamicPDF Merger is simple. Below are steps and sample code showing how to combine three PDF documents into one.

Steps to Combine PDF Files​

  1. Create a MergeDocument object by passing the first PDF file.
  2. Call the append method with the second PDF file.
  3. Repeat the call to the append method any number of times depending on the number of PDFs you need to combine. Optionally you an also specify the pages from the PDF to be appended.
  4. Invoke the Draw method on the Document to output the combined PDF.

Sample code - Java​

MergeDocument document = new MergeDocument("DocumentA.pdf");
document.append("DocumentB.pdf);
document.append("DocumentC.pdf, 1, 2);

document.Draw(@"Output.pdf");

Combine PDFs by Specifying Options​

Steps to Combine PDFs​

  1. Create a MergeOptions object.
  2. Set the options as per your requirement. In the example, we set FormFields to false, so form fields are not appended.
  3. Pass the MergeOptions object into the append method.

Sample code - Java​

// Specify the options
MergeOptions options = MergeOptions.append;
options.setOutLines(false);

// Append a document
document.append("doc-with-outline.pdf", options);

Getting Started​

DynamicPDF Merger Information​

More information can be found here:

Available in Other Platforms​

DynamicPDF Merger PDF Library is available for .NET and COM/AxtiveX platforms. Refer to the respective product pages for more details.