Specify the JPEG image quality

Decreasing the JPG images quality reduces the size of the output file.

To adjust images quality, call the setJpgQuality() method of the PdfViewOptions class. The value must be between 1 (minimum quality) and 100. The default value is 90.

To set the image quality, follow these steps:

  1. Instantiate the Viewer class. Specify the source document path as a constructor parameter.
  2. Instantiate the PdfViewOptions object.
  3. Call the setJpgQuality() method.
  4. Call the View.view() method of the Viewer object. Specify the PdfViewOptions object as the parameter.

The following code snippet shows how to adjust JPG image quality in the output PDF document:

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

try (Viewer viewer = new Viewer("sample.docx")) {
    PdfViewOptions viewOptions = new PdfViewOptions();
    viewOptions.setJpgQuality((byte) 50);
    viewer.view(viewOptions);
}