【问题标题】:Count PDF pages from stdin with Ghostscript (PostScript)使用 Ghostscript (PostScript) 从标准输入计算 PDF 页面
【发布时间】:2014-07-17 12:38:21
【问题描述】:

我在stackoverflow 上找到了如何通过在 shell 上执行以下命令来使用 Ghostscript 计算 PDF 文件的页数

gs -q -dNODISPLAY -c "($PATH_TO_PDF) (r) file runpdfbegin pdfpagecount = quit"')

我想从标准输入获取 pdf。

我会玩一点,但没有成功。

我的做法是:

gs -q -dNODISPLAY - -c "(%stdin) (r) file runpdfbegin pdfpagecount = quit"')

我没有输出。

有什么提示或建议吗?

【问题讨论】:

  • 一周多来第一个有趣的后记问题。

标签: shell ghostscript postscript


【解决方案1】:

您不能使用标准输入中的 PDF 文件,因为 PDF 格式或多或少地使得能够随机访问文件的所有部分变得至关重要。

在 Ghostscript 从标准输入读取 PDF 文件的情况下,它首先将其复制到本地文件,然后处理该文件,因此无论如何它不能从标准输入工作。

简而言之,这是做不到的。

【讨论】:

  • awwww...嗯,谢谢你的回答。我以为我可以避免这种情况。
【解决方案2】:

这行得通:

gs -q -dNODISPLAY -c "($PATH_TO_PDF) (r) file runpdfbegin pdfpagecount = quit";

我认为你尝试使用的问题

gs -q -dNODISPLAY -c "($PATH_TO_PDF) (r) file runpdfbegin pdfpagecount = quit"')

是QUIT后不匹配的右括号

【讨论】:

  • 您实际上可以将 line-separator 放在末尾 ';' —— 干得好。
【解决方案3】:

可以做到的。

String ars = "-q -dNODISPLAY  -dNOPAUSE -sDEVICE=tiffg3  -r150.4 -o" + outputImagesPath + "%d.tiff -sPAPERSIZE=a4 " + inputPDFFile + " -c quit";
Process proc = new Process();
proc.StartInfo.FileName = ghostScriptPath;
proc.StartInfo.Arguments = ars;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
//Raise Your Complete Job Event Here And User Directory.GetFiles("..").Count

【讨论】:

    猜你喜欢
    • 2016-12-02
    • 1970-01-01
    • 2012-03-16
    • 1970-01-01
    • 1970-01-01
    • 2019-05-24
    • 2017-10-21
    • 1970-01-01
    • 2011-03-06
    相关资源
    最近更新 更多