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:

/// <summary>
/// Max width of an output image in pixels.
/// </summary>
public int ImageMaxWidth { get; set; }

/// <summary>
/// Max height of an output image in pixels.
/// </summary>
public int ImageMaxHeight { get; set; }

/// <summary>
/// The width of the output image in pixels.
/// </summary>
public int ImageWidth { get; set; }

/// <summary>
/// The height of an output image in pixels.
/// </summary>
public int ImageHeight { get; set; }
Class SurroundingClass
    ''' <summary>
    ''' Max width of an output image in pixels.
    ''' </summary>
    Public Property ImageMaxWidth As Integer

    ''' <summary>
    ''' Max height of an output image in pixels.
    ''' </summary>
    Public Property ImageMaxHeight As Integer

    ''' <summary>
    ''' The width of the output image in pixels.
    ''' </summary>
    Public Property ImageWidth As Integer

    ''' <summary>
    ''' The height of an output image in pixels.
    ''' </summary>
    Public Property ImageHeight As Integer
End Class

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

  • To render a single image, set ImageWidth/ImageHeight options.
  • To render multiple images, set ImageMaxWidth/ImageMaxHeight options. If an image exceeds these limits, it is resized proportionally.
Warning
If you set the ImageWidth/ImageHeight options, the ImageMaxWidth/ImageMaxHeight options are ignored.

To set the ImageMaxWidth/ImageMaxHeight options, follow these steps:

  1. Instantiate the Viewer object.
  2. Instantiate the PdfViewOptions object.
  3. Set the ImageMaxWidth and/or ImageMaxHeight values;
  4. Call the View method.

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

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

using (Viewer viewer = new Viewer("sample.jpg"))
{
    // Create a PDF file.
    PdfViewOptions viewOptions = new PdfViewOptions();
    
    // Specify the maximum width and height.
    viewOptions.ImageMaxWidth = 800;
    viewOptions.ImageMaxHeight = 600;
    viewer.View(viewOptions);
}
Imports GroupDocs.Viewer.Options
Imports GroupDocs.Viewer
' ...

Module Program
    Sub Main(args As String())
        Using viewer As Viewer = New Viewer("sample.jpg")
            ' Create a PDF file.
            Dim viewOptions As PdfViewOptions = New PdfViewOptions()

            ' Specify the maximum width and height.
            viewOptions.ImageMaxWidth = 800
            viewOptions.ImageMaxHeight = 600
            viewer.View(viewOptions)
        End Using
    End Sub
End Module

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

Binary file (PDF, 590 KB)

Download full output