GroupDocs.Conversion allows you to convert specific pages of a document instead of processing the entire file. This feature is useful when you need to extract or convert only certain sections of a document, reducing processing time and file size.
To convert specific pages from a document, follow these steps:
Initialize the Converter – Create an instance of the Converter class and pass the source document path as a constructor parameter.
Set Convert Options – Instantiate the appropriate ConvertOptions class based on the target format (e.g., PdfConvertOptions, WordProcessingConvertOptions, SpreadsheetConvertOptions, etc.).
Specify Pages to Convert – Use the setPages method of the ConvertOptions instance to define a list of pages to be converted.
Perform Conversion – Call the convert method of the Converter class, passing the output filename and the ConvertOptions instance.
The following Java code snippet demonstrates how to convert only the first and third pages of a Word document (.docx) into a PDF:
importcom.groupdocs.conversion.Converter;importcom.groupdocs.conversion.options.convert.PdfConvertOptions;publicclassConvertSpecificPages{publicstaticvoidconvert(){// Initialize the converter with the source document
Converterconverter=newConverter("annual-review.docx");// Set conversion options for PDF
PdfConvertOptionsoptions=newPdfConvertOptions();// Specify pages to convert (first and third pages)
options.setPages(Arrays.asList(1,3));// Perform the conversion
converter.convert("converted.pdf",options);System.out.println("Selected pages have been successfully converted.");}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.
Supported Formats
The ability to convert specific pages is available for various formats, including:
Faster Processing – Converts only the required pages, reducing processing time.
Smaller File Size – Generates a smaller output file by excluding unnecessary pages.
Focused Output – Useful when working with lengthy documents where only certain pages are relevant.
Conclusion
GroupDocs.Conversion makes it easy to extract and convert specific pages from documents. This functionality is particularly useful for users who need precise control over their document conversions, saving both time and resources.
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.