public static void CreatePngFromPdf(string sPdfFilePath, string sPngFilePath, int iResolutionDPI = 300)
{
try
{
var pdfDocument = new Document(sPdfFilePath);
for (int iPage = 1; iPage <= pdfDocument.Pages.Count; iPage++)
{
string sTiffFilePathPage = string.Format("{0}\\{1}_{2}.png", Path.GetDirectoryName(sPngFilePath), Path.GetFileNameWithoutExtension(sPngFilePath), iPage);
using (FileStream fs = new FileStream(sTiffFilePathPage, FileMode.Create))
{
// Create Resolution object
Resolution resolution = new Resolution(iResolutionDPI);
PngDevice pngDevice = new PngDevice(resolution);
pngDevice.Process(pdfDocument.Pages[iPage], fs);
fs.Close();
}
}
}
catch (Exception ex)
{
throw new Exception(string.Format("Failed to create PNG from PDF file: {0}", sPdfFilePath), ex);
}
}