DEV Community

Atir Tahir
Atir Tahir

Posted on

4

A generic code to convert a file to image format

You can convert any document to Image using following piece of code:

string outputFileTemplate = Path.Combine(outputFolder, "converted-page-{0}.jpg");
SavePageStream getPageStream = page => new FileStream(string.Format(outputFileTemplate, page), FileMode.Create);
using (Converter converter = new Converter("sample.pdf"))
{
    ImageConvertOptions options = new ImageConvertOptions
    {
        Format = ImageFileType.Jpg
    };

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

Quite simple, isn't it? Let's see what conversion options API facilitates.

  • Brightness
  • Contrast
  • FlipMode
  • Gamma
  • Grayscale

and a lot others. ImageFileType defines the output image file type (e.g. PNG, JPG, SVG).
Get more details or post any API related issue here.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

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