Reduce 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 →

On this page

If the output PDF file contains images, you can reduce its size using image compression.

To enable image compression, set the compress_images property to True. The GroupDocs.Viewer compresses all images in the file.

The image_quality property determines the compression ratio. It is a quality value in percent. 100% means original quality.

The following code snippet shows how to compress images in the file:

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PdfViewOptions, PdfOptimizationOptions

def reduce_image_quality():
    # Load document
    with Viewer("sample.docx") as viewer:
        viewOptions = PdfViewOptions("reduce_image_quality/reduced_quality.pdf")
        viewOptions.pdf_optimization_options = PdfOptimizationOptions()
        viewOptions.pdf_optimization_options.compress_images = True
        viewOptions.pdf_optimization_options.image_quality = 50

        viewer.view(viewOptions)

if __name__ == "__main__":
    reduce_image_quality()

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

Binary file (PDF, 483 KB)

Download full output

On this page