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 methods to set or get the image width or/and height:

/**
 * Max width of an output image in pixels. (When converting single image to HTML only)
 */
public int getImageMaxWidth();

/**
 * Max width of an output image in pixels. (When converting single image to HTML only)
 */
public void setImageMaxWidth(int imageMaxWidth);

/**
 * Max height of an output image in pixels. (When converting single image to HTML only)
 */
public int getImageMaxHeight();

/**
 * Max height of an output image in pixels. (When converting single image to HTML only)
 */
public void setImageMaxHeight(int imageMaxHeight);

/**
 * The width of the output image in pixels. (When converting single image to HTML only)
 */
public int getImageWidth();

/**
 * The width of the output image in pixels. (When converting single image to HTML only)
 */
public void setImageWidth(int imageWidth);

/**
 * The height of an output image in pixels. (When converting single image to HTML only)
 */
public int getImageHeight();

/**
 * The height of an output image in pixels. (When converting single image to HTML only)
 */
public void setImageHeight(int imageHeight);

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

  • To render a single image, call setImageWidth/setImageHeight methods.
  • To render multiple images, call setImageMaxWidth/setImageMaxHeight options. If an image exceeds these limits, it is resized proportionally.
Warning
If you set the ImageWidth/ImageHeight options, calls of setImageMaxWidth/setImageMaxHeight methods are ignored.

To call the setImageMaxWidth/setImageMaxHeight methods, follow these steps:

  1. Instantiate the Viewer object.
  2. Instantiate the PdfViewOptions object.
  3. Call the setImageMaxWidth and/or setImageMaxHeight methods;
  4. Call the View.view() method.

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

import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.options.PdfViewOptions;
// ...

try (Viewer viewer = new Viewer("sample.jpg")) {
    PdfViewOptions viewOptions = new PdfViewOptions("result.pdf");
    viewOptions.setImageMaxWidth(800);
    viewOptions.setImageMaxHeight(600);

    viewer.view(viewOptions);
}