GroupDocs.Merger allows to extract pages from source document. The result is a new document that contains only specified pages from the source document.
Here are the steps to extract document pages:
Initialize ExtractOptions class with page numbers that should appear in the resultant document;
Instantiate Merger object with source document path or stream;
Call Save method specifying file path to save resultant document.
The following code sample demonstrates how to extract document pages by specifying exact page numbers:
stringfilePath=@"c:\sample.pdf";stringfilePathOut=@"c:\output\result.pdf";ExtractOptionsextractOptions=newExtractOptions(newint[]{1,4});// Resultant document will contain pages 1 and 4using(Mergermerger=newMerger(filePath)){merger.ExtractPages(extractOptions);merger.Save(filePathOut);}
The following code sample demonstrates how to extract document pages by specifying page numbers range:
stringfilePath=@"c:\sample.pdf";stringfilePathOut=@"c:\output\result.pdf";ExtractOptionsextractOptions=newExtractOptions(1,3,RangeMode.EvenPages);// Resultant document will contain page 2using(Mergermerger=newMerger(filePath)){merger.ExtractPages(extractOptions);merger.Save(filePathOut);}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.