17

是否有免费的C# 库( .dll ) 可以将PDF转换为图像

我试过这个:

https://code.google.com/p/lib-pdf/

但它不起作用,我收到了这个错误:

  Could not load file or assembly 'libpdf.DLL' or one of its dependencies. The specified    module could not be found.

iTextSharp 也没有实现这样的功能..

编辑:

我没有使用 ghost 脚本,因为你必须先在计算机上安装它

但现在我找到了一个解决方案:如果你手动加载 dll 它可以工作

http://ghostscriptnet.codeplex.com/discussions/465418

    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();
       }
   }
4

0 回答 0