Use the PreviewOptions class to manage the preview generation process - specify desired page numbers, image format, etc.
To generate the document preview using GroupDocs.Comparison API, follow these steps:
Create an instance of the Comparer class. Specify the source document path as a constructor parameter.
Add the target document to comparison using the Add method.
The Source and Targets properties of the Comparer object allows you to access source and target documents and provides the GeneratePreview method;
Instantiate the PreviewOptions object. Specify the following parameters:
delegate for each page stream creation (see the CreatePageStream event handler)
image preview format - PNG / JPG / BMP
page numbers to process
custom size of preview images (if needed)
Note
Stream created by the CreatePageStream delegate is disposed automatically when preview image is generated. If you need to implement the custom disposing of the image preview stream, specify the ReleasePageStream argument to clean up resources.
The PreviewOptions class main properties are as follows:
CreatePageStream is a delegate which defines method to create output page preview stream
ReleasePageStream is a delegate which defines method to remove output page preview stream. This is can be used when need advanced control for resources handling
Width is preview image width. Use this property to customize output image width
Height is preview image height. Use this property to customize output image height
PageNumbers defines numbers of pages to be previewed;
PreviewFormat gets or sets the preview image format which provides ability to choose between image quality and size. Use the BMP format for the best image quality. Use the JPG format to produce smallest image size (and faster loading image previews), but with lower quality than BMP. By default GroupDocs.Comparison uses the PNG format to provide appropriate image quality and size.
The following code snippet shows how to generate document previews:
This feature is not supported for WordProcessing documents.
Get page previews and clean resources manually
usingGroupDocs.Comparison;usingGroupDocs.Comparison.Options;usingSystem.IO;// ...// 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);}
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.