Adjust the JPEG image quality

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Viewer MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-viewer -- dnx GroupDocs.Viewer.Mcp --yes
Folders, licensing and more →

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

    viewer.view(viewOptions);
}