Aeseir
Aeseir

Reputation: 8424

ASP Core convert PDF pages to images

I am trying to figure out if its possible to convert PDF document into a series of images. Currently looking to migrate from ASP.NET 4.6 to ASP.CORE and this is so far the roadbloack to it. I cannot seem to find any working examples for ASP Core of this currently.

Appreciate any help i can get.

Upvotes: 3

Views: 2107

Answers (1)

Mason.Chase
Mason.Chase

Reputation: 905

You can use Docnet,

Here is an example code from project:

private static byte[] GetModifiedImage(IPageReader pageReader)
{
    var rawBytes = pageReader.GetImage();

    var width = pageReader.GetPageWidth();
    var height = pageReader.GetPageHeight();

    var characters = pageReader.GetCharacters();

    using (var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb))
    {
        bmp.AddBytes(rawBytes);

        bmp.DrawRectangles(characters);

        using (var stream = new MemoryStream())
        {
            bmp.Save(stream, ImageFormat.Png);

            return stream.ToArray();
        }
    }
}

Hope it helps Cheers

Upvotes: 1

Related Questions