from
reportlab.pdfgen
import
canvas
from
reportlab.pdfbase.ttfonts
import
TTFont
from
reportlab.pdfbase
import
pdfmetrics
from
reportlab.lib
import
colors
fileName
=
'sample.pdf'
documentTitle
=
'sample'
title
=
'Technology'
subTitle
=
'The largest thing now!!'
textLines
=
[
'Technology makes us aware of'
,
'the world around us.'
,
]
image
=
'image.jpg'
pdf
=
canvas.Canvas(fileName)
pdf.setTitle(documentTitle)
pdfmetrics.registerFont(
TTFont(
'abc'
,
'SakBunderan.ttf'
)
)
pdf.setFont(
'abc'
,
36
)
pdf.drawCentredString(
300
,
770
, title)
pdf.setFillColorRGB(
0
,
0
,
255
)
pdf.setFont(
"Courier-Bold"
,
24
)
pdf.drawCentredString(
290
,
720
, subTitle)
pdf.line(
30
,
710
,
550
,
710
)
text
=
pdf.beginText(
40
,
680
)
text.setFont(
"Courier"
,
18
)
text.setFillColor(colors.red)
for
line
in
textLines:
text.textLine(line)
pdf.drawText(text)
pdf.drawInlineImage(image,
130
,
400
)
pdf.save()