Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Merge Word Documents using C#
// Load the source DOCX file
Merger merger = new Merger(@"C:\Files\sample.docx");
// Define join options
JoinOptions joinOptions = new JoinOptions(1, 4, RangeMode.OddPages);
// Add DOCX file to merge with source DOCX
merger.Join(@"C:\Files\sample2.docx", joinOptions);
// Merge DOCX files and save the merged file
merger.Save(@"C:\Files\merged.docx");
// Load the source DOCX file
Merger merger = new Merger(@"C:\Files\sample.docx");
// Add DOCX file to merge with source DOCX
merger.Join(@"C:\Files\sample2.docx");
// Add another DOCX file to merge with source DOCX
merger.Join(@"C:\Files\sample3.docx");
// Merge DOCX files and save the merged file
merger.Save(@"C:\Files\merged.docx");
// Load the source DOCX file
Merger merger = new Merger(@"C:\Files\sample.docx");
// Add DOCX file to merge with source DOCX
merger.Join(@"C:\Files\sample2.docx");
// Set Password
AddPasswordOptions addOptions = new AddPasswordOptions("password");
merger.AddPassword(addOptions);
// Merge DOCX files and save the merged file
merger.Save(@"C:\Files\merged.docx");
// Load the source PDF file
Merger merger = new Merger(@"C:\Files\sample.pdf");
// Add DOCX file to merge with source PDF
merger.Join(@"C:\Files\sample.docx");
// Merge DOCX files and save the merged PDF
merger.Save(@"C:\Files\merged.pdf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment