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


Groups > comp.lang.python > #49174 > unrolled thread

Re: io module and pdf question

Started byMRAB <python@mrabarnett.plus.com>
First post2013-06-25 17:59 +0100
Last post2013-06-25 17:59 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#49174 — Re: io module and pdf question

FromMRAB <python@mrabarnett.plus.com>
Date2013-06-25 17:59 +0100
SubjectRe: io module and pdf question
Message-ID<mailman.3838.1372179590.3114.python-list@python.org>
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
>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web