是否有可能使用iTextSharp的将PDF页面转换为图像? [英] Is it possible to convert PDF page to Image using itextSharp?

查看:2555
本文介绍了是否有可能使用iTextSharp的将PDF页面转换为图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我一直在使用iTextSharp的在dot.net所有PDF相关的项目。
我碰到,我需要的PDF页面转换为图像的要求。
我找不到这样的事情任何样品。我发现,另一种工具的ghostscript能够做到这一点的问题,那就是我是一个共享的主机和功放;我不认为Ghostscript可在服务器上运行在我的本地机器我不得不手动复制鬼脚本DLL文件,这是不可能在一个共享的主机system32目录。

Hi I have been using itextSharp for all pdf related projects in dot.net. I came across a requirement where I need to convert PDF pages to images. I could not find any sample of such a thing. I found that another tool ghostscript is able to do it the problem with that is I am on a shared hosting & I don't think ghostscript will run on server as in my local machine I had to manually copy ghost script dlls to system32 folder which is not possible in a shared hosting.

推荐答案

好吧,我找遍了,发现有一个的NuGet包鬼脚本,所以对我来说问题通过将程序包管理器控制台,并添加鬼脚本新鲜项目解决了(我创建一个新的项目,因为旧的PM>安装封装Ghostscript.NET有各种参考到Win32 DLL文件的Ghostscript)。
所以,回答我的问题是:
1> iTextSharp的不能直接PDF页面转换为图像。
2>在Ghostscript.NET 1.2.0它很容易。下面是一个代码示例。

Ok I searched all over and found out that there is a nuget package for Ghost Script, so problem for me was solved by going to package manager console and adding ghost script to fresh project (I created a fresh project since the old one had all kinds of reference to win32 ghostscript dlls) by "PM> Install-Package Ghostscript.NET". So the answer to my question is: 1.> itextSharp cannot directly convert PDF pages to image. 2.> The "Ghostscript.NET 1.2.0" does it quite easily. Following is a code example.

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

    }

这篇关于是否有可能使用iTextSharp的将PDF页面转换为图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆