[ale] building pdf from python with reportlab

Bob Toxen transam at VerySecureLinux.com
Tue Aug 26 18:44:57 EDT 2014


I've had consistently excellent luck with using groff with -mm (using whatever
fonts are needed, including constant-width fonts if you want ASCII-art)
and then ps2pdf.  The ONLY thing not handled well is ligatures.  Turn
them off at the start of the doc with:

  .lg 0


No dobut someone has a better solution.

Bob Toxen
bob at verysecurelinux.com               [Please use for email to me]
http://www.verysecurelinux.com        [Network&Linux security consulting]
http://www.realworldlinuxsecurity.com [My book:"Real World Linux Security 2/e"]
Quality Linux & UNIX security and SysAdmin & software consulting since 1990.
Quality spam and virus filters.

"One disk to rule them all, One disk to find them. One disk to bring
them all and in the darkness grind them. In the Land of Redmond where
the shadows lie...and the Eye is everwatching"
-- The Silicon Valley Tarot Henrique Holschuh with ... Bob

On Tue, Aug 26, 2014 at 10:37:22AM -0400, jkinney wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> I'm trying to generate a 1-page pdf that has some text and a single
> image (a qrcode) and I'm hitting issues. The docs for reportlab are a
> better than many but still missing key details. The following will
> generate the page, the text starts at the correct location, BUT the
> text runs vertical down the page. I have found nothing that indicates
> how to do that or fix it. By vertical down the page I mean:
> l
> i
> k
> e
> 
> t
> h
> i
> s
> 
> grr! That _really_ messes up ascii art!
> 
> # generate the pdf file from the template, ascii art and the qrcode.png
> files
> # requires python-reportlab
> def gen_pdf(text, asciiblock):
> 
>         from reportlab.pdfgen import canvas
>         from reportlab.lib.units import inch
>         def makeqrpage(canvas):
> 
>                 textobject = canvas.beginText()
>                 textobject.setTextOrigin(inch, 9.5*inch)
>                 textobject.setFont("Helvetica-Bold", 14)
>                 for line in text:
>                         textobject.textLine(line)
>                 canvas.drawText(textobject)
>                 textobject.setTextOrigin(1.5*inch, 6.5*inch)
>                 textobject.setFillGray(0.4)
>                 for line in asciiblock:
>                         textobject.textLine(line)
>                 canvas.drawText(textobject)
>                 canvas.drawImage('qrcode.png', 2.5*inch, 1.5*inch,
> 4.5*inch, 3.5*inch)
>         canvas = canvas.Canvas('qrcode.pdf')
>         makeqrpage(canvas)
>         canvas.showPage()
>         canvas.save()
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1
> 
> iQIcBAEBAgAGBQJT/JuiAAoJEIm+DWlR6PEq+QgQAJbVHnWuU6SMIZqa4GW57ChB
> +sJGxAkf0dX7AcB14+G/ipoZCfwkQrriMEAHqO9deHyZQvPnwXeN1rYGRMC0uKMn
> JiTALxhdCZaj7mX+lOEy8iSsz/kpJ143AMUhY7LkEHbu4q1+kZCzdPuMgrTVUOdP
> 3VaT64OYVmAZ9jxSyelaMy+f8tx0QHroEnKowe4KhMhl7JbIMrgR9/6jBSPnF+0L
> UoX7pWkqvI9lCFKdkoYAKXpDhoJFnj3AlcT14UTUTw2Kyp7ejrPG+t3b5pXvd6Wt
> N4c/6NitssrYogqPHp393Xw0FJF7UiooFFaQLacy+zZzqoV4i9blHoyhqwQDsrHj
> DwlskUcyaj5fP161GbDRwHp+ekLDHyyk2qH8jz1naj1qWEpLuC2l3fN56t1KCRAT
> 87CiA1M4XvE6dFl1MpaZKxlUWMrrImd83UKgjXPrd57wUkS6DSPj522PWc91DrBX
> iBqx0iGGV+gV9jg1rWNgbfRmEJKjjheGDC0v7/J8Xv2YhfLyrTLWBvQAexT2VC39
> hqyT4Cpw5tjDhrCEmIuVK29S/MHTkvEGOLniJaur48Gag1I2i6TyFooM+sjtxq4x
> 5/s24l+ienSxvwIxVgHOjIWcsLf9WCRQblpQHIs913xNY+Eqf0jIpb9rvGON2jNn
> HPcjnzlwRPq9yWFdEeRY
> =4oOE
> -----END PGP SIGNATURE-----
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo


More information about the Ale mailing list