This feature is supported by version 26.11 or greater.
DocumentAssembler.GeneratePreview renders pages of a document to images. The document can be a template, a document assembled by GroupDocs.Assembly, or any other document of a supported format: word processing, spreadsheet, presentation, email or text. PreviewOptions follows the preview options of other GroupDocs products.
A delegate called for every page to get the stream the page image is written to. Passed to the constructor.
ReleasePageStream
An optional delegate called when a page image has been written, to close or process its stream. Passed to the constructor.
PreviewFormat
The image format: PreviewFormats.PNG (the default), PreviewFormats.JPEG or PreviewFormats.BMP.
PageNumbers
The numbers of the pages to render, starting from 1. All pages by default.
Width, Height
The size of page images in pixels. When both are set, pages are scaled to fit that size keeping their aspect ratio, and Resolution is ignored.
Resolution
The resolution of page images in dots per inch, 96 by default.
Rendering Pages of an Assembled Report
The example assembles a report into memory and renders its pages to PNG files:
usingSystem.IO;usingGroupDocs.Assembly;usingGroupDocs.Assembly.Data;DocumentAssemblerassembler=newDocumentAssembler();using(FileStreamtemplate=File.OpenRead("Customer orders.docx"))using(MemoryStreamreport=newMemoryStream()){assembler.AssembleDocument(template,report,newDataSourceInfo(newJsonDataSource("Customers.json"),"customers"));report.Position=0;// A stream is created for every page and released when the page is written.PreviewOptionsoptions=newPreviewOptions(pageNumber=>File.Create($"page{pageNumber}.png"),(pageNumber,pageStream)=>pageStream.Dispose());options.PreviewFormat=PreviewFormats.PNG;options.Resolution=120;// dots per inch; 96 by default// options.PageNumbers = new[] { 1, 2 }; // all pages by defaultassembler.GeneratePreview(report,options);}
Rendering Selected Pages of a Template
To preview a template itself, pass its path. Here the first page is rendered to a JPEG image that fits in 400 × 400 pixels: