DEV Community

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

Posted on

2 2

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.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay