Strange problem with an inline image in a Paragraph

Lele Gaifax <[email protected]>
Newsgroups gmane.comp.python.reportlab.user
Organization Nautilus Entertainments
Message-ID <[email protected]>
Hi all,

I have a problem with adding an inline image in a Paragraph(), using raw
Frame(). My application builds a PDF document using a sequence of
"rectangles", where each rectangle gets drawn by a particular function.

A few days ago I started seeing something completely unexpected and
inexplicable: I have tree such rectangles in a row, each containing a single
image and some text, and one of them comes out with a double image!

Here is an extremely cut down self-contained example script that exhibits the
problem:

    from reportlab.pdfgen.canvas import Canvas
    from reportlab.platypus import Frame, Paragraph
    from reportlab.lib.styles import getSampleStyleSheet
    from reportlab.rl_config import defaultPageSize
    from reportlab.lib.units import cm

    from PIL import Image, ImageDraw


    def go():
        im = Image.new('L', (50, 50))
        draw = ImageDraw.Draw(im)
        draw.line([(0, 0), (50, 50)], fill=100, width=3)
        draw.line([(0, 50), (50, 0)], fill=200, width=3)
        with open('/tmp/strange.jpeg', 'wb') as f:
            im.save(f, 'JPEG')

        styles = getSampleStyleSheet()
        with open("strange.pdf", "wb") as output:
            c = Canvas(output, pagesize=defaultPageSize)

            # This works: a single image appears
            
            f = Frame(1*cm, 2*cm, 1*cm, 1*cm)
            s = styles["Normal"]
            t = '<img src="/tmp/strange.jpeg" valign="middle"/>'
            p = Paragraph(t, s)
            f.addFromList([p], c)

            # This "fails": a "twin" image appears
            
            f = Frame(1*cm, 4*cm, 1*cm, 1*cm)
            s = styles["Normal"]
            t = '<img src="/tmp/strange.jpeg" valign="middle" height="25" width="25"/>'
            p = Paragraph(t, s)
            f.addFromList([p], c)

            c.showPage()
            c.save()


    if __name__ == "__main__":
        go()

Am I missing something, or doing something wrong?

Thanks in advance for any hint,
ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
[email protected]  |                 -- Fortunato Depero, 1929.

_______________________________________________
reportlab-users mailing list
[email protected]
https://pairlist2.pair.net/mailman/listinfo/reportlab-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.