Convert a document to Image - Set horizontal and vertical resolutions

atir_tahir

Atir Tahir

Posted on April 7, 2021

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.

๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
atir_tahir
Atir Tahir

Posted on April 7, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

ยฉ TheLazy.dev

About