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
- Create a
MergeDocument
object by passing the first PDF file. - Call the
append
method with the second PDF file. - 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. - 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
- Create a
MergeOptions
object. - Set the options as per your requirement. In the example, we set FormFields to false, so form fields are not appended.
- 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.
- .NET - DynamicPDF Merger for .NET
- COM/ActiveX - DynamicPDF Merger for COM/ActiveX