[Python] Proper way to add an image file inside a PDF document generated with Reportlab on...

Discussão em 'Python' iniciado por Stack, Agosto 24, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to generate a PDF report using reportlab on App Engine Python.

    But I don't know how to attach an image properly.

    The image is static.

    This is the directory tree of my project.

    [​IMG]

    and this is what I do (inside 'chipas.py') to get the image:

    im = Image('../static/logo.png',1*inch, 1*inch)
    story.append(im)
    ...


    The stack trace I get:


    Traceback (most recent call last): File "C:\Users\Lucas\Dropbox\Desarrollo\Python\windows\AppEngine\google\appengine\ext\webapp_webapp25.py", line 701, in call handler.get(*groups) File "C:\Users\Lucas\Dropbox\Desarrollo\workspace\python\chipas-windows\src\chipas.py", line 1035, in get doc.build(story) File "C:\Users\Lucas\Dropbox\Desarrollo\workspace\python\chipas-windows\src\reportlab\platypus\doctemplate.py", line 1117, in build BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker) File "C:\Users\Lucas\Dropbox\Desarrollo\workspace\python\chipas-windows\src\reportlab\platypus\doctemplate.py", line 880, in build self.handle_flowable(flowables) File "C:\Users\Lucas\Dropbox\Desarrollo\workspace\python\chipas-windows\src\reportlab\platypus\doctemplate.py", line 763, in handle_flowable if frame.add(f, canv, trySplit=self.allowSplitting): File "C:\Users\Lucas\Dropbox\Desarrollo\workspace\python\chipas-windows\src\reportlab\platypus\frames.py", line 159, in _add w, h = flowable.wrap(aW, h) File "C:\Users\Lucas\Dropbox\Desarrollo\workspace\python\chipas-windows\src\reportlab\platypus\flowables.py", line 408, in wrap return self.drawWidth, self.drawHeight File "C:\Users\Lucas\Dropbox\Desarrollo\workspace\python\chipas-windows\src\reportlab\platypus\flowables.py", line 402, in getattr self._setup_inner() File "C:\Users\Lucas\Dropbox\Desarrollo\workspace\python\chipas-windows\src\reportlab\platypus\flowables.py", line 368, in _setup_inner img = self._img File "C:\Users\Lucas\Dropbox\Desarrollo\workspace\python\chipas-windows\src\reportlab\platypus\flowables.py", line 398, in getattr self._img = ImageReader(self._file) File "C:\Users\Lucas\Dropbox\Desarrollo\workspace\python\chipas-windows\src\reportlab\lib\utils.py", line 541, in init if _isPILImage(fileName): File "C:\Users\Lucas\Dropbox\Desarrollo\workspace\python\chipas-windows\src\reportlab\lib\utils.py", line 521, in _isPILImage return isinstance(im,Image.Image) AttributeError: 'NoneType' object has no attribute 'Image' INFO 2012-02-29 19:54:37,276 dev_appserver.py:4247] "GET /pdf?pedido=ahVkZXZ-Y2hpcGFzLWludGhlY2xvdWRyLwsSBlBlZGlkbyIjMjAxMi0wMi0yOSAxOTo1NDoxOHRlc3RAZXhhbXBsZS5jb20M HTTP/1.1" 500 -
    ​

    What's the proper way to add an image file inside a pdf document generated with reportlab? Many thanks in advance!

    Continue reading...

Compartilhe esta Página