From: Hongyi Zhao on
Hi all,

I want to use shell command to judge whether a file is in pdf format
or not. Any hints?
--
..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
From: Ben Finney on
Hongyi Zhao <hongyi.zhao(a)gmail.com> writes:

> I want to use shell command to judge whether a file is in pdf format
> or not. Any hints?

The 'file(1)' command queries file contents and identifies the type of
data they contain.

--
\ “If you continue running Windows, your system may become |
`\ unstable.” —Microsoft, Windows 95 bluescreen error message |
_o__) |
Ben Finney
From: Fred on
On Feb 16, 4:44 am, Hongyi Zhao <hongyi.z...(a)gmail.com> wrote:
> On Tue, 16 Feb 2010 11:27:26 +0000, Ben Bacarisse
>
> <ben.use...(a)bsb.me.uk> wrote:
> >In addition to 'file' you could use the exit code from pdfinfo.  This
> >is part of a suite of PDF manipulating programs that might not be
> >available on your target systems, but it seems worth mentioning.
>
> Excellent tool!  It's also available on my system.  Thanks a lot.

Note that just because the first line of a file begins with "%PDF-"
it does not guarantee that the rest of the file is actually in PDF
format.
So the test can only determine that a file is either *not* PDF, or
that the file is "might be PDF".
--
Fred K
From: Ben Bacarisse on
Hongyi Zhao <hongyi.zhao(a)gmail.com> writes:

> I want to use shell command to judge whether a file is in pdf format
> or not. Any hints?

In addition to 'file' you could use the exit code from pdfinfo. This
is part of a suite of PDF manipulating programs that might not be
available on your target systems, but it seems worth mentioning.

--
Ben.
From: Hongyi Zhao on
On Tue, 16 Feb 2010 11:27:26 +0000, Ben Bacarisse
<ben.usenet(a)bsb.me.uk> wrote:

>In addition to 'file' you could use the exit code from pdfinfo. This
>is part of a suite of PDF manipulating programs that might not be
>available on your target systems, but it seems worth mentioning.

Excellent tool! It's also available on my system. Thanks a lot.
--
..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.