Set image size limits

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 →

The PdfViewOptions class has the following properties to set the image width or/and height:

  • image_max_width (int) - Max width of an output image in pixels.
  • image_max_height (int) - Max height of an output image in pixels.
  • image_width (int) - The width of the output image in pixels.
  • image_height (int) - The height of an output image in pixels.

You can set the width and/or height of the output images. Use one of the following methods:

  • To render a single image, set image_width/image_height options.
  • To render multiple images, set image_max_width/image_max_height options. If an image exceeds these limits, it is resized proportionally.
Warning
If you set the image_width/image_height options, the image_max_width/image_max_height options are ignored.

To set the image_max_width/image_max_height options, follow these steps:

  1. Instantiate the Viewer object.
  2. Instantiate the PdfViewOptions object.
  3. Set the image_max_width and/or image_max_height values;
  4. Call the view method.

The following code snippet shows how to set the output image size limits:

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

def set_image_size_limits():
    # Load document
    with Viewer("sample.jpg") as viewer:
        # Create a PDF file.
        viewOptions = PdfViewOptions("set_image_size_limits/image_with_size_limits.pdf")

        # Specify the maximum width and height.
        viewOptions.image_max_width = 800
        viewOptions.image_max_height = 600
        viewer.view(viewOptions)

if __name__ == "__main__":
    set_image_size_limits()

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

Binary file (PDF, 590 KB)

Download full output