Convert to Image with advanced options

GroupDocs.Conversion provides the ImageConvertOptions class to give you better control over the conversion result when converting to images. Along with common convert options from the base class, the ImageConvertOptions has the following additional options:

  • setFormat specifies desired result document type. Available options are: Tiff, Tif, Jpg, Jpeg, Png, Gig, Bmp, Ico, Psd, Wmf, Emf, Dcm, Webp, Dng, Svg, Jp2, Odg, J2c, J2k, Jpx, Jpf, Jpm, Eps, Cgm, Cdr, Cmx, Dib, Jpc, Jls, DjVu.
  • 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 image rotation angle.
  • setFlipMode specifies image flip mode. 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.options.convert.ImageConvertOptions;
import com.groupdocs.conversion.filetypes.ImageFileType;
import com.groupdocs.conversion.options.convert.ImageFlipModes;
import java.io.FileOutputStream;
import java.io.IOException;
...
        String outputFileTemplate = "ConvertToImageWithAdvancedOptions-converted-page-%s.png";

        try {
            FileOutputStream getPageStream = new FileOutputStream(String.format(outputFileTemplate, 1));

            Converter converter = new Converter("sample.pdf");
            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);

            converter.convert(() -> getPageStream, options);
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }

JpegOptions

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

The following options are available:

  • setQuality sets the 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:

  • 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:

  • 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 PSD version.

WebpOptions

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

The following options are available:

  • setLossless specifies if the compression of the converted image should be lossless.
  • setQuality sets the desired quality of the converted image.