3

这些是我试图实现的步骤:

  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。

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 中没有任何输出。有人知道为什么吗?任何建议都将受到高度赞赏。

4

1 回答 1

3

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

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

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

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

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

于 2009-12-22T05:36:53.063 回答