Rendering to PNG or JPEG
Contents
[
Hide
]Document viewer can operate in different rendering modes, HTML, Image and PDF (see Features Overview for more information). This article will describe on how to view documents in Image mode with Image Viewer.
Image Viewer provides PngViewOptions and JpgViewOptions classes to set specific options for rendering the document into desired image format.
Here are the steps for rendering into image with GroupDocs.Viewer API:
- Create new instance of Viewer class and pass source document path as a constructor parameter.
- Instantiate the PngViewOptions or JpgViewOptions object according to your requirements and specify saving path format for rendered document pages.
- Call view() method of Viewer class instance and pass PngViewOptions or JpgViewOptions to it.
Rendering to PNG
This example shows how to render each document page into PNG image.
try (Viewer viewer = new Viewer("sample.docx")) {
PngViewOptions viewOptions = new PngViewOptions();
viewer.view(viewOptions);
}
Rendering to JPEG
This example shows how to render each document page into JPG image.
try (Viewer viewer = new Viewer("sample.docx")) {
JpgViewOptions viewOptions= new JpgViewOptions();
viewer.view(viewOptions);
}
GroupDocs.Viewer also provides an ability to customize rendering to image by setting additional options. To learn more about caching customization please refer to the following guides: Image Viewer - Add text overlay over images, Image Viewer - Adjust image size, Image Viewer - Adjust quality for JPG and Image Viewer - Get text coordinates