Rendering turns a document into files that a browser or an app can display: HTML pages, a PDF file, or PNG and JPEG images. GroupDocs.Viewer renders more than 190 formats, and all of them the same way: open the document with a Viewer, create the view options of the output you need, and call Viewer.View.
When an output has one file per page, put {0} in the file name: it is replaced with the page number, so page_{0}.png gives page_1.png, page_2.png and so on. A PDF needs no {0}, because every page goes into the one file.
Render a document
The following example renders each page of a Word document to a PNG image:
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...// Load the documentusing(Viewerviewer=newViewer("sample.docx")){// Create a PNG image for each page.// {0} is replaced with the current page number in the file name.PngViewOptionsviewOptions=newPngViewOptions("page_{0}.png");viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())' Load the document
UsingviewerAsViewer=NewViewer("sample.docx")' Create a PNG image for each page.
' {0} is replaced with the current page number in the file name.
DimviewOptionsAsPngViewOptions=NewPngViewOptions("page_{0}.png")viewer.View(viewOptions)EndUsingEndSubEndModule
sample.docx is the sample file used in this example. Click here to download it.
Replace PngViewOptions with JpgViewOptions, PdfViewOptions or HtmlViewOptions.ForEmbeddedResources to get the other outputs; the pages below describe each one.
Render specific pages
To render only some of the pages, pass their numbers to Viewer.View after the view options. The following example renders pages 1 and 3:
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...// Load the documentusing(Viewerviewer=newViewer("sample.docx")){// {0} is replaced with the current page number in the file name.PngViewOptionsviewOptions=newPngViewOptions("page_{0}.png");// Render pages 1 and 3 only.viewer.View(viewOptions,1,3);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())' Load the document
UsingviewerAsViewer=NewViewer("sample.docx")' {0} is replaced with the current page number in the file name.
DimviewOptionsAsPngViewOptions=NewPngViewOptions("page_{0}.png")' Render pages 1 and 3 only.
viewer.View(viewOptions,1,3)EndUsingEndSubEndModule
sample.docx is the sample file used in this example. Click here to download it.
When you render to PDF, the order of the numbers is the order of the pages in the file: see Reorder pages.
More about rendering
Each format has options of its own, such as the hidden slides of a presentation, the layers of a CAD drawing or the folders of an archive. See Document rendering basics. The pages of this section cover the outputs: