2

我有以下内容用于获取 PDF 文档中的总页数:

identify -format %n test.pdf

然后我去除所有非数字字符以从响应中获取单个整数。

有时会产生以下错误,这会导致上面产生错误的页数,因为它们是与响应中的页面无关的其他数字。

   **** Warning: Fonts with Subtype = /TrueType should be embedded.
             The following fonts were not embedded:
                    Arial
                    Arial,Bold
                    Arial,Italic
                    Times New Roman

    **** This file had errors that were repaired or ignored.
    **** The file was produced by:
    **** >>>> Microsoft« Office Word 2007 <<<<
    **** Please notify the author of the software that produced this
    **** file that it does not conform to Adobe's published PDF
    **** specification.

    9

“9”是文档中的页数。

如何抑制警告消息,我尝试使用“-quiet”标志,但仍然产生消息。

4

2 回答 2

2

警告会发送到 stderr,所以一个简单的输出重定向就可以解决问题:

 identify -format %n test.pdf 2>/dev/null
于 2012-10-06T11:00:23.287 回答
2

从识别的手册页:

-quiet 抑制所有警告信息

因此,为了抑制警告消息,您的命令应如下所示:

identify -quiet -format %n test.pdf
于 2019-07-09T16:59:31.030 回答