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 PDF 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 the Viewer object;
  • Instantiate the PdfViewOptions;
  • 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"))
{
    PdfViewOptions viewOptions = new PdfViewOptions("result.pdf");
    
    viewOptions.ImageMaxWidth = 800;
    viewOptions.ImageMaxHeight = 600;

    viewer.View(viewOptions);
}

PdfViewOptions class 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; }

© Aspose Pty Ltd 2001-2022. All Rights Reserved.