GroupDocs.Conversion allows you to convert a specific range of consecutive pages from a document. This feature is useful when you only need a portion of the document instead of converting the entire file.
To convert a set of consecutive pages, follow these steps:
Initialize the Converter
Create an instance of the Converter class and provide the source document path.
Configure Conversion Options
Instantiate the appropriate ConvertOptions class (e.g., PdfConvertOptions, WordProcessingConvertOptions, etc.).
Call the convert() method on the Converter instance, passing the output file name and the ConvertOptions instance.
The following Java example demonstrates how to convert four consecutive pages, beginning from the second page of the document:
importcom.groupdocs.conversion.Converter;importcom.groupdocs.conversion.options.convert.PdfConvertOptions;publicclassConvertConsecutivePages{publicstaticvoidconvert(){// Load the source document
Converterconverter=newConverter("annual-review.docx");// Define conversion options
PdfConvertOptionsoptions=newPdfConvertOptions();options.setPageNumber(2);// Start from page 2
options.setPagesCount(4);// Convert 4 pages
// Perform the conversion
converter.convert("converted.pdf",options);}publicstaticvoidmain(String[]args){convert();}}
annual-review.docx is sample file used in this example. Click here to download it.
converted.pdf is converted attachment PDF document. Click here to download it.
Additional Notes
The page numbering starts at 1, not 0.
If the specified pagesCount exceeds the document’s total page count, conversion will continue until the last page.
This approach applies to different document formats by selecting the appropriate ConvertOptions subclass (e.g., WordProcessingConvertOptions, SpreadsheetConvertOptions).
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.