[reportlab-users] Fwd: [reportlab-team] Fwd: PDF Imaging

Robin Becker robin at reportlab.com
Tue May 20 08:37:13 EDT 2014


Hi Ramas,

1) you are trying to mix platypus flowables (the Image object im) with direct 
drawing to the canvas.

The simplest way to do what you want is probably to use either of the canvas 
methods drawInlineImage or drawImage.

> HI Nick,
>
> Good Morning...
>
> *My code to get image into PDF file,*
>
> from reportlab.pdfgen import canvas
> from reportlab.lib.pagesizes import letter, A4, landscape
> from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
> from reportlab.graphics.shapes import *
> from reportlab.lib import colors
> from reportlab.graphics import renderPDF
> from reportlab.lib.enums import TA_CENTER
> from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
> from reportlab.lib.units import cm, inch
>
> def hello(c):
>     c.setFont('Times-Roman', 26)
>     c.drawString(100,800, "V-LIFE Monthly Report (May 2014)")
>     c.rect(10, 10, 575, 820)
>     c.rect(30,680,520,100)
>
>     im = Image("CompanyLogo.jpg")
>     im.hAlign = 'CENTER'

this is a platypus object, you can use it with a canvas if you are knowledgeable 
about the Flowable api. However, the easiest way to get an image onto a canvas 
is to use something like

        c.drawImage("CompanyLogo.jpg",10,10,520,100)

see reportlab/pdfgen/canvas.py for more details of the available arguments.

>
>     print('Sucessfully done')
>
> c = canvas.Canvas("testPage.pdf")
> hello(c)
> c.showPage()
> c.save()

..........



-------------- next part --------------
_______________________________________________
reportlab-team mailing list
reportlab-team at lists.reportlab.com
http://lists.reportlab.com/cgi-bin/mailman/listinfo/reportlab-team

-------------- next part --------------
A non-text attachment was scrubbed...
Name: CompanyLogo.jpg
Type: image/jpeg
Size: 2657 bytes
Desc: not available
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20140520/4cd7a5c9/attachment.jpg>


More information about the reportlab-users mailing list