Thursday, 15 April 2010

django - python-docx: add picture from the web -



django - python-docx: add picture from the web -

i using python-docx (with django) generate word documents. there way utilize add_picture add together image web rather file system?

in word, when select add together picture, can give url. tried same , write:

document.add_picture("http://icdn4.digitaltrends.com/image/microsoft_xp_bliss_desktop_image-650x0.jpg")

and got error:

ioerror: [errno 22] invalid mode ('rb') or filename: 'http://icdn4.digitaltrends.com/image/microsoft_xp_bliss_desktop_image-650x0.jpg'

not elegant, found solution, based on question in here

my code looks that:

import urllib2, stringio image_from_url = urllib2.urlopen(url_value) io_url = stringio.stringio() io_url.write(image_from_url.read()) io_url.seek(0) try: document.add_picture(io_url ,width=px(150))

and works fine.

python django docx

No comments:

Post a Comment