The following example shows how to generate document page previews:
// Create an instance of Parser class to generate document page previewsusing(Parserparser=newParser(Constants.SamplePdfWithToc)){// Create preview optionsPreviewOptionspreviewOptions=newPreviewOptions(pageNumber=>File.Create(GetOutputPath($"preview_{pageNumber}.png")));// Set PNG as an output image formatpreviewOptions.PreviewFormat=PreviewFormats.PNG;// Set DPI for the output imagepreviewOptions.Dpi=72;// Generate previewsparser.GeneratePreview(previewOptions);}privatestaticstringGetOutputPath(stringfileName){// Create the output directory if necessaryif(!Directory.Exists(Constants.OutputPath)){Directory.CreateDirectory(Constants.OutputPath);}returnPath.Combine(Constants.OutputPath,fileName);}
Note
Spreadsheets are rendered by tiles. See the example bellow.
Here are the steps to generate spreadsheets page previews:
The following example shows how to generate spreadsheet page previews:
// Create an instance of Parser class to generate spreadsheet page previewsusing(Parserparser=newParser(Constants.SampleXlsx)){PageRenderInforenderInfo=null;// Create preview optionsPreviewOptionspreviewOptions=newPreviewOptions(pageNumber=>File.Create(GetOutputPath(renderInfo,pageNumber)));// Set delegate to obtain the render infopreviewOptions.PreviewPageRender=info=>renderInfo=info;// Set PNG as an output image formatpreviewOptions.PreviewFormat=PreviewFormats.PNG;// Set DPI for the output imagepreviewOptions.Dpi=72;// Generate previewsparser.GeneratePreview(previewOptions);}privatestaticstringGetOutputPath(PageRenderInforenderInfo,intpageNumber){// Set the output directory. If the render info is set, then sheets are rendered on its own directorystringoutputDirectory=renderInfo==null?Constants.OutputPath:Path.Combine(Constants.OutputPath,$"preview_{renderInfo.PageNumber}");// Create the output directory if necessaryif(!Directory.Exists(outputDirectory)){Directory.CreateDirectory(outputDirectory);}// Set the file name. If the render info is set, then tile name is {Row}x{Column}.pngstringfileName=renderInfo==null?$"preview_{pageNumber}.png":$"{renderInfo.GetRow(pageNumber)}x{renderInfo.GetColumn(pageNumber)}.png";returnPath.Combine(outputDirectory,fileName);}
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 parse documents and extract data from PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Parser 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.