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
finalStringtestFile="D:\\sample.pdf";// Take preview of the first page
inttestPageNumber=1;// Preview file name
finalStringpreviewFileName=String.format("%s_page%d.png",testFile,testPageNumber);// Load the document to generate preview
finalRedactorredactor=newRedactor(testFile);try{PreviewOptionsoptions=newPreviewOptions(newICreatePageStream(){@Overridepublicjava.io.OutputStreamcreatePageStream(intpageNumber){try{returnnewjava.io.FileOutputStream(previewFileName);}catch(java.io.FileNotFoundExceptionex){System.out.printf("Failed to create preview file %s: \"%s\"\n\n",previewFileName,ex.toString());returnnull;}}});options.setHeight(640);options.setWidth(480);options.setPageNumbers(newint[]{testPageNumber});options.setPreviewFormat(PreviewFormats.Png);redactor.generatePreview(options);System.out.printf("\nPreview for page %d was saved to \"%s\"\n\n",testPageNumber,previewFileName);}finally{redactor.close();}
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.