Convert specific pages

GroupDocs.Conversion also provides the feature to convert just the specified pages. 

To convert specific pages, follow these steps:

  1. Create an instance of the Converter class and pass the source document path as a constructor parameter.
  2. Instantiate the appropriate ConvertOptions class e.g. (PdfConvertOptions, WordProcessingConvertOptions, SpreadsheetConvertOptions, etc.)
  3. Call the setPages method of the ConvertOptions instance with the list of the desired page numbers to be converted.
  4. Call the convert method of the Converter class instance and pass the filename of the converted document and the instance of the ConvertOptions from the previous steps.

The following code snippet shows how to convert the first and the third pages from the source document:

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import java.util.Arrays;
...
Converter converter = new Converter("sample.docx");
PdfConvertOptions options = new PdfConvertOptions();
options.setPages(Arrays.asList( 1, 3));
converter.convert("converted.pdf", options);