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


Groups > comp.lang.python > #49171

RE: io module and pdf question

Date 2013-06-25 11:15 -0500
From <jyoung79@kc.rr.com>
Subject RE: io module and pdf question
Newsgroups comp.lang.python
Message-ID <mailman.3837.1372176924.3114.python-list@python.org> (permalink)

Show all headers | View raw


Thank you Rusi and Christian!

So it sounds like I should read the pdf data in as binary:

--------------------
import os

pdfPath = '~/Desktop/test.pdf'

colorlistData = ''

with open(os.path.expanduser(pdfPath), 'rb') as f:
    for i in f:
        if 'XYZ:colorList' in i:
            colorlistData = i.split('XYZ:colorList')[1]
            break

print(colorlistData)
--------------------

This gives me the error:
TypeError: Type str doesn't support the buffer API

I admit I know nothing about binary, except it's ones and zeroes.  Is there a way to read it in as binary, convert it to ascii/unicode, and then somehow split it by newline characters so that I can pull the appropriate metadata lines out?  For example, XYZ:colorList="DarkBlue,Yellow"

Thanks!

Jay

--

> 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 | NextNext in thread | Find similar | Unroll thread


Thread

RE: io module and pdf question <jyoung79@kc.rr.com> - 2013-06-25 11:15 -0500
  Re: io module and pdf question rusi <rustompmody@gmail.com> - 2013-06-25 09:30 -0700

csiph-web