DEV Community

Cover image for How do you split a Word document into separate pages?
Atir Tahir
Atir Tahir

Posted on

How do you split a Word document into separate pages?

We could split a Word document to separate pages by specifying start and end page number. Secondly, by specifying exact page numbers.
Let’s see both cases in .NET and Java:

Split the document to several one-page documents (by exact page numbers)
.NET

string filePath = @"c:\sample.docx"; 
string filePathOut = @"c:\output\document_{0}.{1}"; 

SplitOptions splitOptions = new SplitOptions(filePathOut, new int[] { 3, 6, 8 }); 

using (Merger merger = new Merger(filePath)) 
{ 
     merger.Split(splitOptions); 
}  
Enter fullscreen mode Exit fullscreen mode

Java

String filePath = "c:\sample.docx"; 
String filePathOut = "c:\output\document_{0}.{1}"; 

PageSplitOptions splitOptions = new PageSplitOptions(filePathOut, new int[] { 3, 6, 8 }); 
Merger merger = new Merger(filePath); 
merger.split(splitOptions); 
Enter fullscreen mode Exit fullscreen mode

Have a look at .NET and Java developers guide. In case of any issue, you could post it on free support forum.

Top comments (0)