[reportlab-users] Printing to an index card

Stephen Boulet stephen at theboulets.net
Sun Jul 31 23:57:58 EDT 2005


I'm trying to print numers on index cards. The pdf looks good in
Acrobat, but when it prints it centers the page as though it were on an
8.5x11 inch sheet.

Is there a way to specify the page size that I'm missing? Thanks.

Stephen

# 152.40 x 101.60 is a 6x4 index card. Number is 1/72*inches

from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter, A4, inch
print inch
f = file('index cards.pdf','wb')
width, height = 432.00,288.00
pagesize = width, height

c = canvas.Canvas(f,
    pagesize=(width, height),
    bottomup = 1,
    verbosity=0)
fontsize = 96

def putnumbers(c, x, y, width, height, fontsize):
    if len(x) == 1:
        divisor1 = 4.
    else:
        divisor1 = 2.
    if len(y) == 1:
        divisor2 = 4.
    else:
        divisor2 = 2.
    c.setFont('Times-Bold',fontsize)
    c.drawString((0.5*inch+0.5*width)/2.-fontsize/divisor1,
0.5*height-fontsize/4.,x)
    c.drawString((width-0.5*inch+0.5*width)/2.-fontsize/divisor2,
0.5*height-fontsize/4.,y)
    c.showPage()

for i in range(0,21,2):
    putnumbers(c, str(i), str(i+1), width, height, fontsize)

c.save()


More information about the reportlab-users mailing list