DEV Community

Cover image for Convert a document to Image - Set horizontal and vertical resolutions
Atir Tahir
Atir Tahir

Posted on

Convert a document to Image - Set horizontal and vertical resolutions

You can convert a file (e.g. Word, PDF, HTML) to and image format, such as, 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 and set the output/resultant image's vertical and horizontal resolutions as follows:

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,
        HorizontalResolution = 300,
        VerticalResolution = 100
    };

    converter.Convert(getPageStream, options);
}
Jpeg
Enter fullscreen mode Exit fullscreen mode

There are a lot of other options that API provides such as setting flip mode, grayscale. For more details, have a look at this article.

Top comments (0)