无需使用特定的C#库即可将PDF转换为JPG /图像

时间:2014-03-19 12:14:50

标签: c# pdf ghostscript ghostscript.net

是否有免费的 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 scrpit,因为你必须先将它安装在计算机上

但是现在我找到了一个解决方案:如果你手动加载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();
       }
   }

0 个答案:

没有答案
相关问题