Specify 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, enable the CompressImages property and set the ImageQuality property of the PdfOptimizationOptions class. The value must be between 1 (minimum quality) and 100. The default value is 90. Without CompressImages, the quality has no effect.

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. Set the PdfViewOptions.PdfOptimizationOptions value to a new PdfOptimizationOptions object.
  4. Set its CompressImages value to true and its ImageQuality value.
  5. Call the 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:

using GroupDocs.Viewer;
using GroupDocs.Viewer.Options;
// ...

using (Viewer viewer = new Viewer("sample.docx"))
{
    // Create view options.
    PdfViewOptions viewOptions = new PdfViewOptions();

    // Specify the JPG image quality.
    viewOptions.PdfOptimizationOptions = new PdfOptimizationOptions();
    viewOptions.PdfOptimizationOptions.CompressImages = true;
    viewOptions.PdfOptimizationOptions.ImageQuality = 50;
    viewer.View(viewOptions);
}
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Options
' ...

Module Program
    Sub Main(args As String())
        Using viewer As Viewer = New Viewer("sample.docx")
            ' Create view options.
            Dim viewOptions As PdfViewOptions = New PdfViewOptions()

            ' Specify the JPG image quality.
            viewOptions.PdfOptimizationOptions = New PdfOptimizationOptions()
            viewOptions.PdfOptimizationOptions.CompressImages = True
            viewOptions.PdfOptimizationOptions.ImageQuality = 50
            viewer.View(viewOptions)
        End Using
    End Sub
End Module

sample.docx is the sample file used in this example. Click here to download it.

Binary file (PDF, 483 KB)

Download full output