Rendering to PNG or JPEG

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:

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);
    }