Skip to content Skip to sidebar Skip to footer

Reportlab [ Platypus ] - Image Does Not Render

I am working on a report that includes a mixture of tables and images. The images [ graphs, actually ] are saved to the filesystem in .png form. The method that actually renders th

Solution 1:

I eventually brought this matter to a close by using a custom Image subclass:

classCustomImage(Image):
"""
Override - to use inline image instead; inexplicable bug with non inline images
"""defdraw(self):
    lazy = self._lazy
    if lazy>=2: self._lazy = 1
    self.canv.drawInlineImage(self.filename,
        getattr(self,'_offs_x',0),
        getattr(self,'_offs_y',0),
        self.drawWidth,
        self.drawHeight
    )
    if lazy>=2:
        self._img = None
        self._lazy = lazy

Saving the graphs in vector graphics formats eg EPS, saving as JPEG, saving as PNG with and without the alpha channel all did not seem to make a difference.

Solution 2:

The optimal solution would be to generate your graphs in a vector format like postscript that is supported by reportlab. A lot of UNIX software can do this out of the box, and on windows you can use the excellent PDFCreator.

If you have to use raster images for your graphs, try converting your images to JPEG format. Those can be easily embedded in a PDF file using the DCTDecode filter. (This is e.g. what jpeg2pdfdoes.)

Post a Comment for "Reportlab [ Platypus ] - Image Does Not Render"