Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49171 > unrolled thread
| Started by | <jyoung79@kc.rr.com> |
|---|---|
| First post | 2013-06-25 11:15 -0500 |
| Last post | 2013-06-25 09:30 -0700 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
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
| From | <jyoung79@kc.rr.com> |
|---|---|
| Date | 2013-06-25 11:15 -0500 |
| Subject | RE: io module and pdf question |
| Message-ID | <mailman.3837.1372176924.3114.python-list@python.org> |
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
[toc] | [next] | [standalone]
| From | rusi <rustompmody@gmail.com> |
|---|---|
| Date | 2013-06-25 09:30 -0700 |
| Message-ID | <6ae0ff4a-10c6-456b-8191-e600f4436b90@googlegroups.com> |
| In reply to | #49171 |
I guess the string constant 'XYZ:colorlist' needs to be a byte-string -- use b prefix? Dunno for sure. Black hole for me -- unicode!
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web