Ho to convert pdf to image using ABCpdf?

132 Views Asked by At

I am trying to convert an uploaded pdf (byte array) to an image using C# in my ASP.NET MVC application. My app is already using ABCpdf package, but I am having hard time finding code example on how to do such conversion using the package. Can anyone advise? Thanks in advance!

Here is my code. I currently get "Parameter not valid" error on the last statement.

HttpPostedFileBase Attachments;
byte[] PdfAttachmentData;

using (var binaryReader = new BinaryReader(Attachments.InputStream))
      {
          PdfAttachmentData= binaryReader.ReadBytes(Attachments.ContentLength);
      }
using (MemoryStream ms = new MemoryStream(PdfAttachmentData))
      {
          Image myImage = Image.FromStream(ms);
      }
1

There are 1 best solutions below

4
On

I am unfamiliar with the library, but is Doc.Rendering.Save(pathToPng) what you're looking for?

Example in the official documentation, in Examples -> PDF Rendering Example.

EDIT :

Solution by OP :

Doc doc = new Doc(); 
doc.Read(ms); doc.Rendering.DotsPerInch = 72; 
for (int i = 1; i <= 1; i++) 
{ 
    doc.PageNumber = i;
    doc.Rect.String = doc.CropBox.String; 
    bitmap = doc.Rendering.GetBitmap(); 
}