2015-05-26 98 views
6

嗨我一直在dot.net中使用itextSharp所有pdf相关项目。 我遇到了需要将PDF页面转换为图像的需求。 我找不到任何这样的事情。我发现另一个工具ghostscript能够做到这一点的问题是我在一个共享的托管&我不认为ghostscript将运行在服务器上,因为在我的本地机器我不得不手动将ghost script dll复制到system32文件夹在共享主机中是不可能的。是否可以使用itextSharp将PDF页面转换为图像?

+0

这是不可能的使用iTextSharp的..你需要使用一些Java脚本库PDF页面转换为图像......你可以给用Phantomjs一试..这是很好的用于此目的,因为我已经使用它。 – immirza

+0

这个问题还不清楚,所以我建议将它改写成实际可以回答的问题。 如果您只需要GhostScript DLL,您可能会发现将它们复制到'bin'文件夹就足以让您在托管系统上访问其功能。 –

+0

请参考以下链接 http://stackoverflow.com/questions/23905169/how-to-convert-pdf-files-to-image – JDK

回答

11

好的,我搜遍了,发现有一个Ghost Script的nuget软件包,所以对我来说问题是通过打包管理器控制台并将ghost脚本添加到新项目中解决的(我创建了一个新的项目,一个有各种各样的参考win32 ghostscript dlls)通过“PM>安装包Ghostscript.NET”。 所以我的问题的答案是: 1.> itextSharp 不能直接将PDF页面转换为图像。 2.>“Ghostscript.NET 1.2.0”很容易做到。以下是一个代码示例。

public void LoadImage(string InputPDFFile,int PageNumber) 
    { 

     string outImageName = Path.GetFileNameWithoutExtension(InputPDFFile); 
     outImageName = outImageName+"_"+PageNumber.ToString() + "_.png"; 


     GhostscriptPngDevice dev = new GhostscriptPngDevice(GhostscriptPngDeviceType.Png256); 
     dev.GraphicsAlphaBits = GhostscriptImageDeviceAlphaBits.V_4; 
     dev.TextAlphaBits = GhostscriptImageDeviceAlphaBits.V_4; 
     dev.ResolutionXY = new GhostscriptImageDeviceResolution(290, 290); 
     dev.InputFiles.Add(InputPDFFile); 
     dev.Pdf.FirstPage = PageNumber; 
     dev.Pdf.LastPage = PageNumber; 
     dev.CustomSwitches.Add("-dDOINTERPOLATE"); 
     dev.OutputPath = Server.MapPath(@"~/tempImages/" + outImageName); 
     dev.Process(); 

    } 
+0

这仍然需要在服务器上安装Ghostscript。 –

+0

从Ghostscript.NET 1.2.1开始,这在Linux上不会出现。 – sunside

相关问题