Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #49132

Re: io module and pdf question

From Christian Gollwitzer <auriocus@gmx.de>
Newsgroups comp.lang.python
Subject Re: io module and pdf question
Date 2013-06-25 09:18 +0200
Organization A noiseless patient Spider
Message-ID <kqbfuh$nbs$1@dont-email.me> (permalink)
References <mailman.3795.1372133932.3114.python-list@python.org> <959e769b-fdfb-49bb-9a61-7056d01a03d4@googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

io module and pdf question <jyoung79@kc.rr.com> - 2013-06-25 04:18 +0000
  Re: io module and pdf question rusi <rustompmody@gmail.com> - 2013-06-24 23:33 -0700
    Re: io module and pdf question Christian Gollwitzer <auriocus@gmx.de> - 2013-06-25 09:18 +0200
  Re: io module and pdf question wxjmfauth@gmail.com - 2013-06-26 07:11 -0700

csiph-web