baa*_*ron 17 c# pdf ghostscript ghostscript.net
是否有免费的C#库(.dll)将PDF转换为图像?
我试过这个:
但它不起作用,我得到了这个错误:
Could not load file or assembly 'libpdf.DLL' or one of its dependencies. The specified module could not be found.
Run Code Online (Sandbox Code Playgroud)
iTextSharp没有实现这样的功能..
编辑:
我没有使用ghost scrpit,因为你必须先在计算机上安装它
但现在我找到了一个解决方案:如果你加载manualy它的工作原理
public void PDFToImage(string file, string outputPath, int dpi)
{
string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
Ghostscript.NET.Rasterizer.GhostscriptRasterizer rasterizer = null;
Ghostscript.NET.GhostscriptVersionInfo vesion = new Ghostscript.NET.GhostscriptVersionInfo(new Version(0, 0, 0), path + @"\gsdll32.dll", string.Empty, Ghostscript.NET.GhostscriptLicense.GPL);
using (rasterizer = new Ghostscript.NET.Rasterizer.GhostscriptRasterizer())
{
rasterizer.Open(file, vesion, false);
for (int i = 1; i <= rasterizer.PageCount; i++)
{
string pageFilePath = Path.Combine(outputPath, Path.GetFileNameWithoutExtension(file) + "-p" + i.ToString() + ".jpg");
Image img = rasterizer.GetPage(dpi, dpi, i);
img.Save(pageFilePath, ImageFormat.Jpeg);
}
rasterizer.Close();
}
}
Run Code Online (Sandbox Code Playgroud)