Convert to Image with advanced options

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

  • Format 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.
  • Width specifies desired image width after conversion.
  • Height specifies desired image height after conversion.
  • HorizontalResolution specifies desired image horizontal resolution after conversion.
  • VerticalResolution specifies desired image vertical resolution after conversion.
  • Grayscale specifies if true converted image will be grayscaled.
  • RotateAngle specifies image rotation angle.
  • FlipMode specifies image flip mode. Available options are: None, FlipX, FlipY, FlipXY.
  • Brightness adjusts image brightness.
  • Contrast adjusts image contrast.
  • Gamma adjusts image gamma.
  • JpegOptions contains JPEG specific convert options.
  • TiffOptions contains TIFF specific convert options.
  • PsdOptions contains PSD specific convert options.
  • WebpOptions contains WebP specific convert options.
  • UsePdf. Sometimes, for better rendering and elements positioning the source document should be converted to PDF first. If this property is set to true, the input firstly is converted to PDF and after that to desired format.

The following code snippet shows how to convert to image with advanced options:

string outputFileTemplate = Path.Combine("c:\output", "converted-page-{0}.png");
SavePageStream getPageStream = page => new FileStream(string.Format(outputFileTemplate, page), FileMode.Create);
using (Converter converter = new Converter("sample.pdf"))
{
    ImageConvertOptions options = new ImageConvertOptions
    {
        Format = ImageFileType.Png,
        FlipMode = ImageFlipModes.FlipY,
        Brightness = 50,
        Contrast = 50,
        Gamma = 0.5F,
        Grayscale = true,
        HorizontalResolution = 300,
        VerticalResolution = 100
    };
    
    converter.Convert(getPageStream, options);
}

JpegOptions

JpegOptions is subset of ImageConvertOptions which allow enhanced control over conversions to JPEG format. 

The following options are available:

  • Quality specifies desired image quality.
  • ColorMode sets JPEG color mode. Available options are: Rgb, YCbCr, Cmyk, Ycck, Grayscale.
  • Compression sets JPEG compression methods. Available options are: Baseline, Progressive, Lossless, JpegLs.

TiffOptions

TiffOptions is subset of  ImageConvertOptions which allow enhanced control over conversions to TIFF format. 

The following options are available:

  • Compression sets TIFF compression method. Available options are: None, Lzw, Ccitt3, Ccitt4, Rle.

PsdOptions

PsdOptions is subset of  ImageConvertOptions which allow enhanced control over conversions to PSD format. 

The following options are available:

  • ChannelBitsCount sets bits count per channel.
  • ChannelsCount sets color channels count.
  • ColorMode sets PSD color mode. Available options are: Bitmap, Grayscale, Indexed, Rgb, Cmyk, Multichannel, Duotone, Lab.
  • Compression sets PSD compression method. Available options are: Raw, Rle, ZipWithoutPrediction, ZipWithPrediction.
  • Version sets desired PSD version.

WebpOptions

WebpOptions is subset of  ImageConvertOptions which allow enhanced control over conversions to WebP format. 

The following options are available:

  • Lossless sets the compression of the converted image will be lossless.
  • Quality sets set the quality of converted image.