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


Groups > comp.lang.python > #49171

RE: io module and pdf question

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <jyoung79@kc.rr.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'binary': 0.07; 'error:': 0.07; 'received:mail.rr.com': 0.07; 'encode': 0.09; 'indexes': 0.09; 'newline': 0.09; 'objects,': 0.09; 'subject:module': 0.09; 'subject:question': 0.10; 'api': 0.11; "'rb')": 0.16; 'binary,': 0.16; 'binary.': 0.16; 'offsets': 0.16; 'received:10.128': 0.16; 'received:71.74': 0.16; 'received:71.74.56': 0.16; 'received :hrndva-omtalb.mail.rr.com': 0.16; 'set,': 0.16; 'typeerror:': 0.16; 'appropriate': 0.16; 'bit': 0.19; 'split': 0.19; 'import': 0.22; 'case.': 0.24; "doesn't": 0.30; 'characters': 0.30; 'gives': 0.31; 'lines': 0.31; "skip:' 10": 0.31; 'usually': 0.31; 'thanks!': 0.32; 'another': 0.32; 'text': 0.33; 'received:rr.com': 0.33; 'except': 0.35; 'case,': 0.35; 'convert': 0.35; 'objects': 0.35; 'but': 0.35; 'there': 0.35; 'possible': 0.36; 'should': 0.36; 'example,': 0.37; 'skip:- 20': 0.37; 'received:10': 0.37; 'christian': 0.38; 'thank': 0.38; 'to:addr:python-list': 0.38; 'pdf': 0.39; 'received:71': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'read': 0.60; 'most': 0.60; 'from:no real name:2**0': 0.61; 'break': 0.61; 'skip:o 30': 0.61; 'first': 0.61; 'such': 0.63; 'therefore': 0.72; 'funny': 0.74; 'pdf.': 0.84; 'rusi': 0.91
Authentication-Results hrndva-omtalb.mail.rr.com smtp.user=jyoung79@kc.rr.com; auth=pass (LOGIN)
X-Authority-Analysis v=2.0 cv=Du3UCRD+ c=1 sm=0 a=05ChyHeVI94A:10 a=IkcTkHD0fZMA:10 a=ayC55rCoAAAA:8 a=KGjhK52YXX0A:10 a=5_gfI98ybrwA:10 a=r9KjfefjOmqKuQZLOZ8A:9 a=QEXdDO2ut3YA:10 a=CgQWzgnTVNMdl59y9Vr9mg==:117
X-Cloudmark-Score 0
X-Authenticated-User jyoung79@kc.rr.com
Date Tue, 25 Jun 2013 11:15:20 -0500
From <jyoung79@kc.rr.com>
To python-list@python.org
Subject RE: io module and pdf question
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Priority 3 (Normal)
Sensitivity Normal
X-Originating-IP
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3837.1372176924.3114.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1372176924 news.xs4all.nl 15903 [2001:888:2000:d::a6]:43447
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:49171

Show key headers only | 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