Set image size limits

GroupDocs.Viewer also provides the feature to set limits for width/height for the output image. Follow the below steps to achieve this functionality. If you want to render single image to HTML you can set width/height for the output image. If you set ImageMaxWidth/ImageMaxHeight options, if the image exceeds one of these limits - it will be resized proportionally.

  • Instantiate theViewer object;
  • Instantiate the HtmlViewOptions;
  • Set ImageMaxWidth and/or ImageMaxHeight values;
  • Call View method.
  • The following code sample shows how to set the output image size limits when rendering the document.
using (Viewer viewer = new Viewer("sample.jpg"))
{
    HtmlViewOptions viewOptions = new HtmlViewOptions.ForEmbeddedResources("result_{0}.html");
    //HtmlViewOptions viewOptions = new HtmlViewOptions.ForExternalResources("page_{0}.html", "page_{0}_{1}", "page_{0}_{1}");
    
    viewOptions.ImageMaxWidth = 800;
    viewOptions.ImageMaxHeight = 600;

    viewer.View(viewOptions);
}

HtmlViewOptionsclass has the following properties to set the image width/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; }