Convert all PDF Pages to PNG Image in C#.NET using Aspose.PDF

Hi,
I want convert all pages of pdf to png images.i have many times triyed your sample code pdf to png and pdf to tiff but every time i got only first or last page render finally.
sample code
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{

Aspose.Pdf.Devices.Resolution resolution = new Aspose.Pdf.Devices.Resolution(300);

Aspose.Pdf.Devices.PngDevice pngDevice = new Aspose.Pdf.Devices.PngDevice(resolution);

pngDevice.Process(pdfDocument.Pages[pageCount], ms4);
bytes11 = ms4.GetBuffer();
bytes33 = AppendArrays(bytes11, bytes22);
bytes22 = bytes33;
ms4.Close();
}


public byte[] AppendArrays(byte[] a, byte[] b)
{
byte[] c = new byte[a.Length + b.Length]; // just one array
//allocation
System.Buffer.BlockCopy(a, 0, c, 0, a.Length);
System.Buffer.BlockCopy(b, 0, c, a.Length, b.Length);
return c;
}

Hi Amrish,


Thanks for your inquiry. Please check following code sample to convert all PDF pages to PNG. Hopefully it will help you to accomplish the task.

Document pdfDocument
= new Document(myDir

  • “inputfile.pdf”);<o:p></o:p>

for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)

{

using (FileStream imageStream = new FileStream(myDir + string.Format("{0}_page{1}.png", "Output", pageCount), FileMode.Create))

{

//create PNG device with specified attributes

//Width, Height, Resolution, Quality

//Quality [0-100], 100 is Maximum

//create Resolution object

Resolution resolution = new Resolution(70);

PngDevice pngDevice = new PngDevice(resolution);

//convert a particular page and save the image to stream

pngDevice.Process(pdfDocument.Pages[pageCount], imageStream);

//close stream

imageStream.Close();

}

}

Please feel free to contact us for any further assistance.


Best Regards,