Set image size limits

The HtmlViewOptions 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; }

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 HtmlViewOptions 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 (Viewer viewer = new Viewer("sample.jpg"))
{
    // Create an HTML file.
    var viewOptions = HtmlViewOptions.ForEmbeddedResources();
    // Specify the maximum width and height.
    viewOptions.ImageMaxWidth = 800;
    viewOptions.ImageMaxHeight = 600;
    viewer.View(viewOptions);
}