Use the PreviewOptions class to manage the generation process: specify desired page numbers, image format, etc.
To generate a document preview, follow these steps:
Create an instance of the Annotator class. Specify the source document path as a parameter. The Document property of the Annotator class provides access to source document and implements GeneratePreview method.
Instantiate the PreviewOptions class. Follow these steps:
a. for each page, delegate stream creation (see the CreatePageStream event handler);
b. specify the image preview format - PNG / JPG / BMP,
c. specify page numbers to process;
d. set the custom size of preview images (if needed).
Note
Stream created by the CreatePageStream delegate are disposed automatically once after generation of preview image. To implement the custom image preview stream disposing, you have to specify an additional argument ReleasePageStream to clean up resources.
PageNumbers - Page numbers that will be previewed;
PreviewFormat gets or sets the preview image format. Use the BMP format should be used for the best image quality. Use the JPG format in case of strict requirements to image size, but with lower quality than BMP. By default GroupDocs.Annotation uses the PNG format which is a golden mean between image quality and size.
RenderComments is an option to show or hide comments. By default it is true. Set it to false if you do not need to show comments. This property affects only on WordProcessing documents. The RenderComments value impacts any document comments.
RenderAnnotations is an option to show or hide annotations.By default it is true. Set it to false if you do not need to show annotations.
By default, GroupDocs.Annotation deletes the image stream immediately after creating and rendering the document page. If necessary, you can implement a custom method to perform this operation.
// Method should match with ReleasePageStream delegate signatureprivatevoidUserReleaseStreamMethod(intpageNumber,Streamstream){Console.WriteLine($"Releasing memory for page: {pageNumber}");stream.Close();}using(Annotatorannotator=newAnnotator("input.pdf")){PreviewOptionspreviewOptions=newPreviewOptions(pageNumber=>{varpagePath=$"D:/result_{pageNumber}.png";returnFile.Create(pagePath);});previewOptions.PreviewFormat=PreviewFormats.PNG;previewOptions.PageNumbers=newint[]{1,2,3,4};previewOptions.Height=100;previewOptions.Width=80;// here we set delegate target methodpreviewOptions.ReleasePageStream=UserReleaseStreamMethod;annotator.Document.GeneratePreview(previewOptions);}
Show and hide replies for WordsProcessing documents
Use the boolean RenderComments property to show comments when rendering image preview.
Note
This feature is supported for WordProcessign documents only.
The default value of the property is true. To hide comments, set it to false. This property applies to all comments.
The following code snippet shows how to render an image preview without comments:
GroupDocs.Annotation v20.11 and later allows you to specify the columns you want to generate on the sheet you selected. To do this, use the WorksheetColumns property.
Note
This feature is supported for CellsProcessign documents only.
The following code snippet shows how to set the list of columns to render: