GroupDocs.Signature provides PreviewOptions class to specify different options to manage document pages preview generation process. The feature also supports archives previewing.
Here are the steps to generate document preview with GroupDocs.Signature:
Create new instance of Signature class and pass source document path as a constructor parameter.
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 ReleaseStream to clean up resources.
privatestaticvoidReleasePageStream(PreviewPageDatapageData,StreampageStream){pageStream.Dispose();stringimageName="image-"+pageData.PageNumber+".jpg";stringimageFilePath=Path.Combine("GeneratePreviewFolder",imageName);Console.WriteLine("Image file {0} is ready for preview",imageFilePath);}
Generate document preview from stream with custom stream releasing delegate
publicstaticvoidGetPreview(){using(varstream=File.OpenRead("sample.pdf")){using(Signaturesignature=newSignature("sample.pdf")){// create preview options objectPreviewOptionspreviewOption=newPreviewOptions(GeneratePreview.CreatePageStream){PreviewFormat=PreviewOptions.PreviewFormats.JPEG,};// generate previewsignature.GeneratePreview(previewOption);}}}privatestaticStreamCreatePageStream(PreviewPageDatapageData){stringimageName="image-"+pageData.PageNumber+".jpg";stringimageFilePath=Path.Combine("GeneratePreviewFolder",imageName);varfolder=Path.GetDirectoryName(imageFilePath);if(!Directory.Exists(folder)){Directory.CreateDirectory(folder);}returnnewSystem.IO.FileStream(imageFilePath,FileMode.Create);}privatestaticvoidReleasePageStream(PreviewPageDatapageData,StreampageStream){pageStream.Dispose();stringimageName="image-"+pageData.PageNumber+".jpg";stringimageFilePath=Path.Combine("GeneratePreviewFolder",imageName);Console.WriteLine("Image file {0} is ready for preview",imageFilePath);}
Creating a document preview with custom Resolution
// The path to the documentsstringfilePath="sample.pdf";using(Signaturesignature=newSignature(filePath)){intresolution=96;// create preview options object// You can reuse CreatePageStream and ReleasePageStream methods from the previous examplePreviewOptionspreviewOption=newPreviewOptions(CreatePageStream,ReleasePageStream,resolution){PreviewFormat=PreviewOptions.PreviewFormats.JPEG};// generate previewsignature.GeneratePreview(previewOption);}
Advanced Usage Topics
To learn more about document eSign features, please refer to the advanced usage section.
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples: