Adjust the JPEG image quality

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

To adjust images quality, call the setQuality() property of the JpgViewOptions 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 JpgViewOptions object.
  3. Call the setQuality() method.
  4. Call the View.view() method of the Viewer object. Specify the JpgViewOptions object as the parameter.

The following code snippet shows how to adjust quality of the output JPG image:

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

try (Viewer viewer = new Viewer("sample.docx")) {
    JpgViewOptions viewOptions = new JpgViewOptions();
    viewOptions.setQuality((byte) 50);