A generic code to convert a file to image format

atir_tahir

Atir Tahir

Posted on October 1, 2020

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.

💖 💪 🙅 🚩
atir_tahir
Atir Tahir

Posted on October 1, 2020

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

Sign up to receive the latest update from our blog.

Related