[reportlab-users] Dynamic page sizes

Robin Becker robin at reportlab.com
Tue Oct 18 04:44:20 EDT 2011


On 17/10/2011 18:30, Glenn Linderman wrote:

> I publish poetry in PDF format, because friends with iOS devices and iBooks

> software have informed me that the PDF format is great for use with iBooks...

> each page can contain one poem, and double-tapping the screen causes iBooks to

> "zoom to width" of the text, presenting a nice, screen-filling,

> vertically-scrolling-if-needed page containing the poem at the largest font size

> that avoids line breaks.

>

> I generate the PDF files using 8.5x11 paper size, and 10 point font.

>

> The question: How could I generate the PDF file with variant page sizes (widths

> primarily, but possibly height as well), such that each poem would have a page

> size that just fits the poem? I speculate this would avoid the need for the

> double-tap when viewing on iOS devices.

>

> Glenn

........
Glenn,

what method do you use to create the standard letter size documents? ReportLab
has both page oriented and document oriented mechanisms built in.

If you use a Canvas ie page oriented then it's possible to change the page size
that the canvas will use.

#######
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase.pdfmetrics import registerFont
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.colors import green
registerFont(TTFont("Vera", "Vera.ttf"))
registerFont(TTFont("VeraBI", "VeraBI.ttf"))
c = Canvas('helloworld.pdf', pagesize=(300,500))
c.setFont('Vera', 10)
c.drawString(100, 200, u'Hello World')
c.showPage()
c.setPageSize((400,600))
c.setFont('Vera', 20)
c.setFillColor(green)
c.drawString(100, 300, u'Hello World')
c.save()
#######

if you use the document oriented layout then page sizes are normally determined
by a page template so you have to switch the template before the next page throw
etc etc
--
Robin Becker


More information about the reportlab-users mailing list