Render to PNG or JPEG
When rendering to PNG/JPG, GroupDocs.Viewer renders each page of the source document as a separate PNG or JPG image.
To render files to PNG/JPG, follow these steps:
- Create an instance of the Viewer class. Specify the source document path as a constructor parameter.
- Instantiate the PngViewOptions or JpgViewOptions object. Specify a path to save the rendered pages.
- Call the View method of the Viewer object. Specify the PngViewOptions or JpgViewOptions object as the parameter.
The following code snippet shows how to render a .docx document to PNG image:
using (Viewer viewer = new Viewer("sample.docx"))
{
// Create a PNG file.
PngViewOptions viewOptions = new PngViewOptions();
viewer.View(viewOptions);
}
The following code snippet shows how to render a .docx document to JPG image:
using (Viewer viewer = new Viewer("sample.docx"))
{
// Create a JPG file.
JpgViewOptions viewOptions= new JpgViewOptions();
viewer.View(viewOptions);
}
For details, please refer to the following pages: