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 in 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.
try (Viewer viewer = new Viewer("sample.jpg")) {
PdfViewOptions viewOptions = new PdfViewOptions("result.pdf");
viewOptions.setImageMaxWidth(800);
viewOptions.setImageMaxHeight(600);
viewer.view(viewOptions);
}
In PdfViewOptions have following methods to set single image width/height in PDF.
/**
* 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);
Note: If you set Width/Height in options, MaxWidth/MaxHeight options will be ignored.