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 set MaxWidth/MaxHeight options, if the image exceeds one of these limits - it will be resized proportionally.
Instantiate the Viewer object;
Instantiate the PngViewOptions or JpgViewOptions;
Set MaxWidth and/or MaxHeight 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")) {
JpgViewOptions viewOptions = new JpgViewOptions("result_{0}.jpg");
//PngViewOptions viewOptions = new PngViewOptions("result_{0}.png");
viewOptions.setMaxWidth(800);
viewOptions.setMaxHeight(600);
viewer.view(viewOptions);
}
PngViewOptions and JpgViewOptions implement special interface IMaxSizeOptions, which contain properties for size limits.
/**
* Limits of image size options interface.
*/
public interface IMaxSizeOptions {
/**
* Max width of an output image in pixels.
*/
int getMaxWidth();
/**
* Max width of an output image in pixels.
*/
int setMaxWidth();
/**
* Max height of an output image in pixels.
*/
int getMaxHeight();
/**
* Max height of an output image in pixels.
*/
int setMaxHeight();
}
Note: If you set Width/Height in options, MaxWidth/MaxHeight options will be ignored.