【问题标题】:Converting PDF to a collection of images on the server using GhostScript使用 GhostScript 将 PDF 转换为服务器上的图像集合
【发布时间】:2009-12-21 16:31:21
【问题描述】:

这些是我想要实现的步骤:

  1. 在服务器上上传 PDF 文档。
  2. 使用 GhostScript 将 PDF 文档转换为一组图像(每一页都转换为一个图像)。
  3. 将图像集合发送回客户端。

到目前为止,我对#2很感兴趣。

首先,我下载了 gswin32c.exegsdll32.dll 并设法手动将 PDF 转换为图像集合(我打开 cmd 并运行下面的命令):

gswin32c.exe -dSAFER -dBATCH -dNOPAUSE -sDEVICE=jpeg -r150 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dMaxStripSize=8192 -sOutputFile=image_%d.jpg somepdf.pdf

然后我想,我将 gswin32c.exegsdll32.dll 放入我的 web 项目的 ClientBin 中,并通过进程运行 .exe。 p>

System.Diagnostics.Process process1 = new System.Diagnostics.Process();
process1.StartInfo.WorkingDirectory = Request.MapPath("~/");
process1.StartInfo.FileName = Request.MapPath("ClientBin/gswin32c.exe"); 
process1.StartInfo.Arguments = "-dSAFER -dBATCH -dNOPAUSE -sDEVICE=jpeg -r150 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dMaxStripSize=8192 -sOutputFile=image_%d.jpg somepdf.pdf"
process1.Start(); 

很遗憾,ClientBin 中没有任何输出。有人知道为什么吗?任何建议都将受到高度赞赏。

【问题讨论】:

    标签: asp.net ghostscript


    【解决方案1】:

    我已经尝试过您的代码,它似乎工作正常。我建议检查以下内容:

    1. 验证您的 somepdf.pdf 是否在 gs 进程的工作文件夹中或在命令行中指定文件的完整路径。通过执行以下操作查看 ghostscript 的输出也很有用:

      .... process1.StartInfo.RedirectStandardOutput = true; process1.StartInfo.UseShellExecute = false; process1.Start(); // 读取输出 字符串输出 = process1.StandardOutput.ReadToEnd(); ... process1.WaitForExit(); ...

      如果 gs 找不到您的文件,您将在输出流中收到“错误:/undefinedfilename in (somepdf.pdf)”。

    2. 另一个建议是继续执行脚本,而无需等待 gs 进程完成并生成结果 image_N.jpg 文件。我想添加 process1.WaitForExit 应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-14
      • 2012-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-29
      • 1970-01-01
      相关资源
      最近更新 更多