Convert to Image with advanced options

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.

OptionDescription
setFormat()Specifies the desired image format for the output, such as JPEG, PNG, BMP, or GIF.
setWidth()Specifies desired image width after conversion.
setHeight()Specifies desired image height after conversion.
setHorizontalResolution()Specifies desired image horizontal resolution after conversion.
setVerticalResolution()Specifies desired image vertical resolution after conversion.
setGrayscale()Specifies if true the converted image will be saved in grayscale
setRotateAngle()Specifies the angle to rotate the image, if needed.
setFlipMode()Allows flipping the image horizontally or vertically. Available options are: None, FlipX, FlipY, FlipXY
setBrightness()Adjusts image brightness.
setContrast()Adjusts image contrast.
setGamma()Adjusts image gamma.
setJpegOptions()Contains JPEG-specific convert options.
setTiffOptions()Contains TIFF-specific convert options.
setPsdOptions()Contains PSD-specific convert options.
setWebpOptions()Contains WebP-specific convert options.
setUsePdf()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:

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.filetypes.ImageFileType;
import com.groupdocs.conversion.options.convert.ImageConvertOptions;
import com.groupdocs.conversion.options.convert.ImageFlipModes;

public class ConvertToImageWithAdvancedOptions {
    public static void convert() {
        // Initialize the converter with the source document
        try(Converter converter = new Converter("professional-services.pdf")) {
            // Instantiate the ImageConvertOptions
            ImageConvertOptions options = new ImageConvertOptions();
            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);
        }
    }

    public static void main(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.

JpegOptions

The JpegOptions is a subset of the ImageConvertOptions providing enhanced control over conversions to JPEG format.

The following options are available:

OptionDescription
setQuality()Specifies desired quality of the converted image.
setColorMode()Sets JPEG color mode. Available options are: Rgb, YCbCr, Cmyk, Ycck, Grayscale.
setCompression()Sets JPEG compression methods. Available options are: Baseline, Progressive, Lossless, JpegLs

TiffOptions

The TiffOptions is a subset of the ImageConvertOptions providing enhanced control over conversions to TIFF format.

The following options are available:

OptionDescription
setCompression()Sets TIFF compression method. Available options are: None, Lzw, Ccitt3, Ccitt4, Rle.

PsdOptions

The PsdOptions is a subset of the ImageConvertOptions providing enhanced control over conversions to PSD format.

The following options are available:

OptionDescription
setChannelBitsCount()Sets bits count per channel.
setChannelsCount()Sets color channels count.
setColorMode()Sets PSD color mode. Available options are: Bitmap, Grayscale, Indexed, Rgb, Cmyk, Multichannel, Duotone, Lab.
setCompression()Sets PSD compression method. Available options are: Raw, Rle, ZipWithoutPrediction, ZipWithPrediction.
setVersion()Specifies desired PSDversion.

WebpOptions

The WebpOptions is a subset of the ImageConvertOptions providing enhanced control over conversions to WebP format.

The following options are available:

OptionDescription
setLossless()Specifies if the compression of the converted image should be lossless.
setQuality()Sets the desired quality of the converted image.

For more detailed information on the ImageConvertOptions class and its properties, please refer to the official API reference.

By utilizing these options, you can effectively control the image conversion process to meet your specific needs.