Im trying to have a multiple page pdf be turn into multiple png files shouldn´t the code im using work or am i missing something here is some code.
protected void PdfToPng(string filepdf, int width, int height)
{
string pdfFile = "";
string fileName = Path.GetFileName(filepdf);
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
DirectoryInfo AnexoDirectory = new DirectoryInfo(PathForPdf);
FileInfo[] filesInDir = AnexoDirectory.GetFiles("*" + fileNameWithoutExtension + ".pdf");
foreach (FileInfo foundFile in filesInDir)
{
pdfFile = foundFile.FullName;
}
// Open PDF document
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(pdfFile);
// Loop through each page
foreach (var page in pdfDocument.Pages)
{
// Create file stream for output image
using (FileStream imageStream = new FileStream(PathForPdf + @"\\" + string.Format((fileNameWithoutExtension + ".png"), page.Number), FileMode.Create))
{
// Create Resolution object
Aspose.Pdf.Devices.Resolution resolution = new Resolution(1200);
// Create Png device with specified attributes
// Width, Height, Resolution
PngDevice PngDevice = new PngDevice(width, height, resolution);
// Convert a particular page and save the image to stream
PngDevice.Process(page, imageStream);
// Close stream
imageStream.Close();
}
}
ShowPng(filepdf);
}