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


Groups > comp.lang.python > #49174

Re: io module and pdf question

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'binary': 0.07; 'error:': 0.07; 'string': 0.09; 'encode': 0.09; 'indexes': 0.09; 'newline': 0.09; 'objects,': 0.09; 'prefix': 0.09; 'strings.': 0.09; 'subject:module': 0.09; 'subject:question': 0.10; 'api': 0.11; 'python': 0.11; "'rb')": 0.16; 'binary,': 0.16; 'binary.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'literals': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'offsets': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'set,': 0.16; 'typeerror:': 0.16; 'unicode.': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'split': 0.19; 'import': 0.22; 'header:User-Agent:1': 0.23; 'case.': 0.24; 'unicode': 0.24; 'header:In-Reply-To:1': 0.27; "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; 'except': 0.35; 'case,': 0.35; 'convert': 0.35; 'objects': 0.35; 'received:84': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'possible': 0.36; 'should': 0.36; 'example,': 0.37; 'skip:- 20': 0.37; 'christian': 0.38; 'thank': 0.38; 'to:addr:python-list': 0.38; 'pdf': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'read': 0.60; 'most': 0.60; 'break': 0.61; 'skip:o 30': 0.61; 'first': 0.61; 'such': 0.63; 'header:Reply-To:1': 0.67; 'default': 0.69; 'reply- to:no real name:2**0': 0.71; 'therefore': 0.72; 'funny': 0.74; 'pdf.': 0.84; 'reply-to:addr:python.org': 0.84; 'rusi': 0.91; 'hand,': 0.93
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=RZapVTdv c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=oyR3mlnJdzkA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=5_gfI98ybrwA:10 a=ayC55rCoAAAA:8 a=r9KjfefjOmqKuQZLOZ8A:9 a=wPNLvfGTeEIA:10
X-AUTH mrabarnett:2500
Date Tue, 25 Jun 2013 17:59:49 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130509 Thunderbird/17.0.6
MIME-Version 1.0
To python-list@python.org
Subject Re: io module and pdf question
References <20130625161520.OWWUK.343277.root@hrndva-web23-z01>
In-Reply-To <20130625161520.OWWUK.343277.root@hrndva-web23-z01>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
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.3838.1372179590.3114.python-list@python.org> (permalink)
Lines 55
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1372179590 news.xs4all.nl 15943 [2001:888:2000:d::a6]:35528
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:49174

Show key headers only | View raw


On 25/06/2013 17:15, jyoung79@kc.rr.com wrote:
> 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"
>
In Python 2, string literals like '' are by default bytestrings. If you
want a Unicode string you need to add the prefix u, so u''.

In Python 3, string literals like '' are by default Unicode. If you
want a bytestring you need to add the prefix b, so b''.

Python 2 was lax when mixing bytestrings with Unicode strings.

Python 3, on the other hand, insists that you know the difference: is
it text (Unicode) or binary data (bytestring)?

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


Thread

Re: io module and pdf question MRAB <python@mrabarnett.plus.com> - 2013-06-25 17:59 +0100

csiph-web