delegate for each page stream creation (see event handler CreatePageStream);
image preview format - PNG / JPG / BMP;
page numbers to process;
custom size of preview images (if needed).
Note
Stream that were created by CreatePageStream delegate will be disposed automatically once after generation of preview image. If you need to implement custom image preview stream disposing you have to pass additional argument ReleasePageStream to clean up resources.
CreatePageStream - Delegate which defines method to create output page preview stream;
ReleasePageStream - Delegate which defines method to remove output page preview stream. This is can be used when need advanced control for resources handling.
Width - Preview image width. This property used when need customize output image width;
Height - Preview image height. This property used when need customize output image height;
PageNumbers - Page numbers that will be previewed;
PreviewFormat - Gets or sets the preview image format which provides ability to choose between image quality and size. BMP format should be used for the best image quality. JPG format will be useful in case of strict requirements to image size - it produces smallest image size (and faster loading image previews), but with lower quality than BMP. By default PNG format is selected - which is a golden mean between image quality and size.
The following code snippet demonstrates how to generate document previews.
In some cases it may be useful to set specific image size during document pages preview generation. For example, to generate document pages thumbnails - small images that is a compressed preview image of the original image that is used as a placeholder. The main advantage of such thumbnail images is their reduced file size compared to the original page image.
The following code snippet demonstrates how to set specific size for preview images.
NOTE: This feature is not supported for WordProcessing documents yet.
Get page previews with manual resource cleaning
By default, after generating and rendering document page preview image stream will be immediately disposed. However there is an ability to implement custom method for handling this operation.
// Method should match with ReleasePageStream delegate signatureprivatevoidUserReleaseStreamMethod(intpageNumber,Streamstream){Console.WriteLine($"Releasing memory for page: {pageNumber}");stream.Close();}using(Comparercomparer=newComparer("source.docx")){comparer.Add("target.docx");comparer.Compare("result.docx");Documentdocument=newDocument(File.OpenRead("result.docx"));PreviewOptionspreviewOptions=newPreviewOptions(pageNumber=>{varpagePath=Path.Combine("C:\", $"result_{pageNumber}.png");
returnFile.Create(pagePath);});previewOptions.PreviewFormat=PreviewFormats.PNG;previewOptions.PageNumbers=newint[]{1,2};// here we set delegate target methodpreviewOptions.ReleasePageStream=UserReleaseStreamMethod;document.GeneratePreview(previewOptions);}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
Along with full-featured .NET library we provide simple, but powerful free Apps. You are welcome to compare your DOC or DOCX, XLS or XLSX, PPT or PPTX, PDF, EML, EMLX, MSG and other documents with free to use online GroupDocs Comparison App.
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.