To convert documents to images with advanced options using GroupDocs.Conversion for Java, you can utilize the ImageConvertOptions class. This class provides various properties to customize the image output according to your requirements.
Sometimes, for better rendering and element positioning the source document should be converted to PDF first. If this property is set to true, the input is first converted to PDF format and after that to the desired format.
The following code snippet shows how to convert to an image with advanced options:
importcom.groupdocs.conversion.Converter;importcom.groupdocs.conversion.filetypes.ImageFileType;importcom.groupdocs.conversion.options.convert.ImageConvertOptions;importcom.groupdocs.conversion.options.convert.ImageFlipModes;publicclassConvertToImageWithAdvancedOptions{publicstaticvoidconvert(){// Initialize the converter with the source document
try(Converterconverter=newConverter("professional-services.pdf")){// Instantiate the ImageConvertOptions
ImageConvertOptionsoptions=newImageConvertOptions();options.setFormat(ImageFileType.Png);options.setFlipMode(ImageFlipModes.FlipY);options.setBrightness(50);options.setContrast(50);options.setGamma(0.5F);options.setGrayscale(true);options.setHorizontalResolution(300);options.setVerticalResolution(100);options.setPageNumber(1);options.setPagesCount(1);// Convert to image with the specified options
converter.convert("converted_with_options.png",options);}}publicstaticvoidmain(String[]args){convert();}}
professional-services.pdf is sample file used in this example. Click here to download it.
converted_with_options.png is converted PNG document. Click here to download it.
In this example, the Converter class is initialized with the source document. The ImageConvertOptions are then configured to set the output format to PNG, define the dimensions, resolution, rotation angle, flip mode and etc. Finally, the convert method is called to perform the conversion with the specified options.