public class PdfToImageConverter
{
public PdfToImageConverter(string filePath)
{
MagickNET.SetGhostscriptDirectory(filePath+"Lib");
MagickNET.SetTempDirectory(filePath + "\Temp");
}
public int ConvertFileToImages(string filePath, string destinationPath)
{
int noofPages = 0;
MagickReadSettings magickReadSettings = new MagickReadSettings();
magickReadSettings.Density = new Density(300, 300);
using (MagickImageCollection magickImageCollection = new MagickImageCollection())
{
magickImageCollection.Read(filePath, magickReadSettings);
int page = 1;
noofPages = magickImageCollection.Count;
foreach (MagickImage magickImage in magickImageCollection)
{
magickImage.Format = MagickFormat.Png;
string imageFilePath = string.Concat(destinationPath,"file-", page, ".png");
magickImage.Write(imageFilePath);
page++;
}
}
return noofPages;
}
}
Share this page on
10
People Like(s) This Page
Permalink
comments powered by Disqus