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:

  1. Create an instance of the Viewer class. Specify the source document path as a constructor parameter.
  2. Instantiate the PngViewOptions or JpgViewOptions object. Specify a path to save the rendered pages.
  3. Call the View.view() method of the Viewer object. Specify the PngViewOptions or JpgViewOptions object as the parameter.

Rendering to PNG

The following code snippet shows how to render a .docx document to PNG image:

import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.options.PngViewOptions;
// ...

try (Viewer viewer = new Viewer("sample.docx")) {
    PngViewOptions viewOptions = new PngViewOptions();
    viewer.view(viewOptions);
}

Rendering to JPEG

The following code snippet shows how to render a .docx document to JPG image:

import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.options.JpgViewOptions;
// ...

try (Viewer viewer = new Viewer("sample.docx")) {
    JpgViewOptions viewOptions= new JpgViewOptions();
    viewer.view(viewOptions);
}

For details, please refer to the following pages: