Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I add a png to a PDF with report lab
    primarykey
    data
    text
    <p>I'm working with report lab, I can't get a way to add png image with platypus this is some sample code from here <a href="http://www.tylerlesmann.com/2009/jan/28/writing-pdfs-python-adding-images/" rel="nofollow">http://www.tylerlesmann.com/2009/jan/28/writing-pdfs-python-adding-images/</a>, with the error for append that png</p> <p>Could you help me to get it working?</p> <pre><code>#!/usr/bin/env python import os import urllib2 from reportlab.lib.pagesizes import letter from reportlab.platypus import SimpleDocTemplate, Image filename = './python-logo.png' def get_python_image(): """ Get a python logo image for this example """ if not os.path.exists(filename): response = urllib2.urlopen( 'http://www.python.org/community/logos/python-logo.png') f = open(filename, 'w') f.write(response.read()) f.close() get_python_image() doc = SimpleDocTemplate("image.pdf", pagesize=letter) parts = [] parts.append(Image(filename)) doc.build(parts) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /media/Felipe/B1wt/&lt;ipython-input-21-1c3c466b9184&gt; in &lt;module&gt;() 22 parts = [] 23 parts.append(Image(filename)) ---&gt; 24 doc.build(parts) 25 /usr/lib/python2.7/site-packages/reportlab/platypus/doctemplate.pyc in build(self, flowables, onFirstPage, onLaterPages, canvasmaker) 1115 if onLaterPages is _doNothing and hasattr(self,'onLaterPages'): 1116 self.pageTemplates[1].beforeDrawPage = self.onLaterPages -&gt; 1117 BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker) 1118 1119 def progressCB(typ, value): /usr/lib/python2.7/site-packages/reportlab/platypus/doctemplate.pyc in build(self, flowables, filename, canvasmaker) 878 try: 879 first = flowables[0] --&gt; 880 self.handle_flowable(flowables) 881 handled += 1 882 except: /usr/lib/python2.7/site-packages/reportlab/platypus/doctemplate.pyc in handle_flowable(self, flowables) 761 canv = self.canv 762 #try to fit it then draw it --&gt; 763 if frame.add(f, canv, trySplit=self.allowSplitting): 764 if not isinstance(f,FrameActionFlowable): 765 self._curPageFlowableCount += 1 /usr/lib/python2.7/site-packages/reportlab/platypus/frames.pyc in _add(self, flowable, canv, trySplit) 157 h = y - p - s 158 if h&gt;0: --&gt; 159 w, h = flowable.wrap(aW, h) 160 else: 161 return 0 /usr/lib/python2.7/site-packages/reportlab/platypus/flowables.pyc in wrap(self, availWidth, availHeight) 406 def wrap(self, availWidth, availHeight): 407 #the caller may decide it does not fit. --&gt; 408 return self.drawWidth, self.drawHeight 409 410 def draw(self): /usr/lib/python2.7/site-packages/reportlab/platypus/flowables.pyc in __getattr__(self, a) 400 return self._img 401 elif a in ('drawWidth','drawHeight','imageWidth','imageHeight'): --&gt; 402 self._setup_inner() 403 return self.__dict__[a] 404 raise AttributeError("&lt;Image @ 0x%x&gt;.%s" % (id(self),a)) /usr/lib/python2.7/site-packages/reportlab/platypus/flowables.pyc in _setup_inner(self) 366 height = self._height 367 kind = self._kind --&gt; 368 img = self._img 369 if img: self.imageWidth, self.imageHeight = img.getSize() 370 if self._lazy&gt;=2: del self._img /usr/lib/python2.7/site-packages/reportlab/platypus/flowables.pyc in __getattr__(self, a) 396 if a=='_img': 397 from reportlab.lib.utils import ImageReader #this may raise an error --&gt; 398 self._img = ImageReader(self._file) 399 del self._file 400 return self._img /usr/lib/python2.7/site-packages/reportlab/lib/utils.pyc in __init__(self, fileName, ident) 539 self._transparent = None 540 self._data = None --&gt; 541 if _isPILImage(fileName): 542 self._image = fileName 543 self.fp = getattr(fileName,'fp',None) /usr/lib/python2.7/site-packages/reportlab/lib/utils.pyc in _isPILImage(im) 519 def _isPILImage(im): 520 try: --&gt; 521 return isinstance(im,Image.Image) 522 except ImportError: 523 return 0 AttributeError: 'NoneType' object has no attribute 'Image' </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload