Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Merge PDF Files using Java
// Create PdfFileEditor object
PdfFileEditor fileEditor = new PdfFileEditor();
// First PDF file
InputStream stream1 = new FileInputStream("file1.pdf");
// Second PDF file
InputStream stream2 = new FileInputStream("file2.pdf");
// OutputStream for merged PDF
OutputStream outstream = new FileOutputStream("merged.pdf");
// Merge PDF files
fileEditor.concatenate(stream1, stream2, outstream);
// Create PdfFileEditor object
PdfFileEditor fileEditor = new PdfFileEditor();
String[] files = new String[] { "file1.pdf", "file2.pdf", "pdf3.pdf" };
// Merge multiple PDF files
fileEditor.concatenate(files, "merged-pdf.pdf");
// Create PDF editor
PdfFileEditor fileEditor = new PdfFileEditor();
// Merge two PDF files
fileEditor.concatenate("file1.pdf", "file2.pdf", "merged-pdf.pdf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.