On Fri, Jan 10, 2014 at 11:12 PM, Victor Stinner
<victor.stin...@gmail.com>wrote:

>
> What not building "10 0 obj ... stream" and "endstream endobj" in
> Unicode and then encode to ASCII? Example:
>
> data = b''.join((
>   ("%d %d obj ... stream" % (10, 0)).encode('ascii'),
>   binary_image_data,
>   ("endstream endobj").encode('ascii'),
> ))
>

The key is "encode to ASCII" which means that the result is bytes. Then,
there is this "11 0 obj" which should also be bytes. But it has no
"binary_image_data" - only lots of numbers waiting to be somehow converted
to bytes. I already mentioned the problems with ".encode('ascii')" but it
does not stop here. Numbers may appear not only inside "streams" but almost
anywhere: in the header there is PDF version, an image has to have "width"
and "height", at the end of PDF there is a structure containing offsets to
all of the objects in file. Basically, to ".encode('ascii')" every possible
number is not exactly simple or pretty.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to