Get document page preview

In GroupDocs.Redaction, Redactor class supports rendering of the document preview in on of these image formats:

  • JPEG Image
  • Portable Network Graphics
  • Bitmap Image File

The following example demonstrates how to get a single page preview of the document.

// Test file
final String testFile = "D:\\sample.pdf";
// Take preview of the first page
int testPageNumber = 1;
// Preview file name
final String previewFileName = String.format("%s_page%d.png", testFile, testPageNumber);
// Load the document to generate preview
final Redactor redactor = new Redactor(testFile);
    PreviewOptions options = new PreviewOptions(new ICreatePageStream() { 
        public createPageStream(int pageNumber) { 
            try {
                return new; 
            } catch ( ex) {
                System.out.printf("Failed to create preview file %s: \"%s\"\n\n", previewFileName, ex.toString());
                return null;
    options.setPageNumbers(new int[] { testPageNumber });
    System.out.printf("\nPreview for page %d  was saved to \"%s\"\n\n", testPageNumber, previewFileName);
finally { redactor.close(); }