// For complete examples and data files, please go to https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-Java
try {
// Setup GroupDocs.Viewer config
ViewerConfig config = Utilities.getConfiguration();
// Create image handler
ViewerImageHandler imageHandler = new ViewerImageHandler(config);
String guid = fileName;
// Options to convert 1, 3, 5, 6, 8 page numbers
ImageOptions options = new ImageOptions();
options.setPageNumbersToConvert(listPagesToConvert);
List<PageImage> pages = imageHandler.getPages(guid, options);
for (PageImage page : pages) {
Utilities.saveAsImage(page.getPageNumber() + "_" + fileName, "png", page.getStream());
}
} catch (Exception exp) {
System.out.println("Exception: " + exp.getMessage());
exp.printStackTrace();
}