是否可以使用 itextSharp 将 PDF 页面转换为图像?
Is it possible to convert PDF page to Image using itextSharp?
您好,我在 dot.net 中的所有 pdf 相关项目中都使用了 itextSharp。
我遇到了一个需要将 PDF 页面转换为图像的需求。
我找不到这样的东西的任何样本。我发现另一个工具 ghostscript 能够做到这一点,问题是我在共享主机上,我认为 ghostscript 不会像在本地机器上那样在服务器上 运行 我不得不手动复制 ghost 脚本 dll到 system32 文件夹,这在共享主机中是不可能的。
好的,我到处搜索,发现有一个 Ghost Script 的 nuget 包,所以我的问题通过转到包管理器控制台并将 ghost 脚本添加到新项目(我创建了一个新项目,因为旧的 "PM> Install-Package Ghostscript.NET" 对 win32 ghostscript dll 进行了各种引用)。
所以我的问题的答案是:
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();
}
您好,我在 dot.net 中的所有 pdf 相关项目中都使用了 itextSharp。 我遇到了一个需要将 PDF 页面转换为图像的需求。 我找不到这样的东西的任何样本。我发现另一个工具 ghostscript 能够做到这一点,问题是我在共享主机上,我认为 ghostscript 不会像在本地机器上那样在服务器上 运行 我不得不手动复制 ghost 脚本 dll到 system32 文件夹,这在共享主机中是不可能的。
好的,我到处搜索,发现有一个 Ghost Script 的 nuget 包,所以我的问题通过转到包管理器控制台并将 ghost 脚本添加到新项目(我创建了一个新项目,因为旧的 "PM> Install-Package Ghostscript.NET" 对 win32 ghostscript dll 进行了各种引用)。 所以我的问题的答案是: 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();
}