Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Merge Word Documents using Java
Merge Word Documents using Java
1. Java API for Merging Word Documents
2. Merge Word Documents using Java
3. Combine Specific Pages of Word Documents using Java
4. Merge and Secure with Password using Java
5. Merge Word Document into PDF using Java
// Initialize API
Merger merger = new Merger("C:\\Files\\merger\\sample.docx");
// Define join options
JoinOptions joinOptions = new JoinOptions(1, 2);
// Merge
merger.join("C:\\Files\\merger\\sample2.docx", joinOptions);
// Save the merged file
merger.save("C:\\Files\\merger\\output.docx");
// Initialize API
Merger merger = new Merger("C:\\Files\\sample.docx");
// Merge files
merger.join("C:\\Files\\sample2.docx");
merger.join("C:\\Files\\sample3.docx");
// Set Password
AddPasswordOptions addOptions = new AddPasswordOptions("password");
merger.addPassword(addOptions);
// Save the merged file
merger.save("C:\\Files\\output.docx");
// Initialize API
Merger merger = new Merger("C:\\Files\\sample.docx");
// Merge files
merger.join("C:\\Files\\sample2.docx");
merger.join("C:\\Files\\sample3.docx");
// Save the merged file
merger.save("C:\\Files\\output.docx");
// Initialize API
Merger merger = new Merger("C:\\Files\\sample.pdf");
// Merge files
merger.join("C:\\Files\\sample.docx");
// Save the merged file
merger.save("C:\\Files\\output.pdf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment