Optimize the PDF file resources

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

Resource optimization allows you to reduce the size of the output PDF file. While optimizing, GroupDocs.Viewer may reduce the image size or quality, remove notes or form fields, remove objects, fonts, or personal information from a document, and so on.

The following code snippet shows how to optimize the PDF file by default:

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

def optimize_pdf_resources():
    # Load document
    with Viewer("sample.docx") as viewer:
        viewOptions = PdfViewOptions("optimize_pdf_resources/optimized_resources.pdf")
        viewOptions.pdf_optimization_options = PdfOptimizationOptions()

        viewer.view(viewOptions)

if __name__ == "__main__":
    optimize_pdf_resources()

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

Binary file (PDF, 719 KB)

Download full output

On this page