Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用iTextSharp将PDF页面绘制到System.Drawing.Image中?_C#_Image_Pdf_Itextsharp - Fatal编程技术网

C# 如何使用iTextSharp将PDF页面绘制到System.Drawing.Image中?

C# 如何使用iTextSharp将PDF页面绘制到System.Drawing.Image中?,c#,image,pdf,itextsharp,C#,Image,Pdf,Itextsharp,我对使用iTextSharp有点陌生。我有一个工作中的PDF文档库,我需要将其复制到图像中(每页一个图像)并进行处理。这些PDF包含文本、光栅图像和矢量图像,可能还有更多内容。我不太熟悉PDF结构,我宁愿在购买PDF包之前使用iTextSharp 我曾使用C#上的iTextSharp从每个PDF文档中提取文本和光栅图像,但尝试将它们渲染成图像会产生混合结果,如果存在矢量图形,我无法轻松提取和渲染它们 很抱歉,我对PDF internal works和iTextSharp缺乏了解,但是有没有一种方

我对使用iTextSharp有点陌生。我有一个工作中的PDF文档库,我需要将其复制到图像中(每页一个图像)并进行处理。这些PDF包含文本、光栅图像和矢量图像,可能还有更多内容。我不太熟悉PDF结构,我宁愿在购买PDF包之前使用iTextSharp

我曾使用C#上的iTextSharp从每个PDF文档中提取文本和光栅图像,但尝试将它们渲染成图像会产生混合结果,如果存在矢量图形,我无法轻松提取和渲染它们

很抱歉,我对PDF internal works和iTextSharp缺乏了解,但是有没有一种方法可以使用iTextSharp将每个PDF页面绘制到System.Drawing.Image对象,就像它们在PDF阅读器程序中显示的那样?如果有一种方法,比如
System.Drawing.Bitmap RenderPage(PdfReader reader,int-iPage)
,那就太好了


谢谢大家。任何帮助都将不胜感激。

我找到了使用另一个库的方法。我使用了Ghostscript.NET

Ghostscript.NET是Ghostscript库本机代码的.NET包装器,因此,它可能无法在Windows RT设备上工作,因为它需要实际的本机代码DLL才能工作

本网站提供了通过NuGet软件包安装Ghostscript.NET的说明:

安装包后,需要Ghostscript本机代码DLL。要获得它,请首先从下面的链接中安装Ghostscript,然后在安装目录中找到gsdll32.dll并将其复制到安全的地方:

这个DLL是32位的。如果您正在为64位编程,则应下载并安装64位版本。获取DLL后,您可以卸载Ghostscript,因为DLL是独立的

最后,我编写了以下代码(假设Ghostscript本机DLL与应用程序位于同一路径上)以将PDF页面呈现到System.Drawing.Images中:

string sDLLPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),
    "gsdll32.dll");
GhostscriptVersionInfo gvi = new GhostscriptVersionInfo(sDLLPath);
using (GhostscriptRasterizer rasterizer = new GhostscriptRasterizer())
{
    rasterizer.Open("sample.pdf", gvi, false);

    int dpi_x = 96;
    int dpi_y = 96;
    for (int i = 1; i <= rasterizer.PageCount; i++)
    {
        Image img = rasterizer.GetPage(dpi_x, dpi_y, i);
        // System.Drawing.Image obtained. Now it can be used at will.
        // Simply save it to storage as an example.
        img.Save(Path.Combine("C:\\Temp", "page_" + i + ".png")),
            System.Drawing.Imaging.ImageFormat.Png);
    }
}
string sDLLPath=Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),
“gsdll32.dll”);
GhostscriptVersionInfo gvi=新的GhostscriptVersionInfo(sDLLPath);
使用(GhostscriptRasterizer光栅化器=新的GhostscriptRasterizer())
{
打开(“sample.pdf”,gvi,false);
int dpi_x=96;
int dpi_y=96;
对于(int i=1;i