我发现 Ghostscript 能够将 PDF 转换为图像格式。
I tried PDF 到图像转换器但无法清楚地理解它。
我已经安装了gs905w64.exe
但当我尝试add reference
对于我的网络应用程序,我收到此错误。
A reference to gsdll32.dll could not be added. No type libraries were found in the component.
您不需要向您的项目添加任何 DLL 引用。
首先下载gs910w32.exe应用程序文件
然后将其安装到您的本地计算机。
获取已安装的.exe文件的位置
例如:-
“C:\ Program Files(x86)\ gs \ gs8.64 \ bin \ gswin32.exe”
在您的 C# 应用程序中将其用作:
private void PdfToJpg(string inputPDFFile, string outputImagesPath)
{
string ghostScriptPath = @"C:\Program Files (x86)\gs\gs8.64\bin\gswin32.exe";
String ars = "-dNOPAUSE -sDEVICE=jpeg -r102.4 -o" + outputImagesPath + "%d.jpg -sPAPERSIZE=a4 " + inputPDFFile;
Process proc = new Process();
proc.StartInfo.FileName = ghostScriptPath;
proc.StartInfo.Arguments = ars;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
}
如果您输入的 PDF 文件名有空格,则需要将参数更改为
String ars = "-dNOPAUSE -sDEVICE=jpeg -r102.4 -o" + outputImagesPath + "%d.jpg -sPAPERSIZE=a4 " +"\"" + inputPDFFile + "\"";
您可以使用 -r 标志在参数中指定输出图像的纵横比。
如果您使用“-r300”,图像的宽度将为 3000 像素,高度将相应改变,根据上面的参数,您将获得 1024 到 768 尺寸的 jpg 图像。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)