Am 25.06.13 08:33, schrieb rusi:
On Tuesday, June 25, 2013 9:48:44 AM UTC+5:30, jyou...@kc.rr.com
wrote:
1. Is there another way to get metadata out of a pdf without having
to install another module? 2. Is it safe to assume pdf files should
always be encoded as latin-1 (when trying to read it this way)? Is
there a chance they could be something else?
If your code is binary open in binary mode (mode="rb") rather than
choosing a bogus encoding. You then have to make your strings also
binary (b-prefix) Also I am surprised that it works at all. Most
pdfs are compressed I thought??
PDFs are a binary format, yes. But they are not, as a whole, compressed.
They are made up of "objects", which can be referred to and crosslinked,
and these objects are represented as ASCII strings. Some of these can
specify a "decoding filter". Examples for the filter include zlib
compression (/FlateDecode) and jpeg compression (/DCTDecode).
Most of the PDF objects are therefore not encoded. It is, however,
possible to include a PDF into another PDF and to encode it, but that's
a rare case. Therefore the metadata can usually be read in text mode.
However, to correctly find all objects, the xref-table indexes offsets
into the PDF. It must be treated binary in any case, and that's the
funny reason for the first 3 characters of the PDF - they must include
characters with the 8th bit set, such that FTP applications treat it as
binary.
Christian
--
http://mail.python.org/mailman/listinfo/python-list