[reportlab-users] Dimensions, line lengths
Michael Hipp
Michael at Hipp.com
Fri Jan 5 19:32:40 EST 2007
The program below is a hacked-up version of what appears in the 2.0 User's
Guide section 5.2 (p. 56). I'm trying to draw lines that start 0.25" from the
left and extend 7.0" on US letter. The key lines are flagged with #***. But on
screen and on print the line starts some 0.55" from the left and the line is
only 6.55" long. What am I doing wrong?
I've attached the resulting PDF and the program.
Thanks,
Michael
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.rl_config import defaultPageSize
from reportlab.lib.units import inch
from reportlab.platypus.flowables import Flowable, KeepTogether
from reportlab.lib.pagesizes import letter, A4
defaultPageSize = letter
PAGE_HEIGHT=defaultPageSize[1]; PAGE_WIDTH=defaultPageSize[0]
styles = getSampleStyleSheet()
def myFirstPage(canvas, doc):
canvas.saveState()
canvas.setFont('Helvetica-Bold',16)
canvas.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT-inch*0.5, "Howdy World")
canvas.setFont('Helvetica',9)
canvas.drawCentredString(PAGE_WIDTH/2.0, 0.25*inch, "Page %d" % doc.page)
canvas.restoreState()
def myLaterPages(canvas, doc):
canvas.saveState()
canvas.setFont('Helvetica',9)
canvas.drawCentredString(PAGE_WIDTH/2.0, 0.25*inch, "Page %d" % doc.page)
canvas.restoreState()
class DividerLine(Flowable):
def __init__(self):
self.xoffset = 0.0
self.size=4
self.scale = 1.0
def wrap(self, *args):
return (self.xoffset, self.size)
def draw(self):
canvas = self.canv
canvas.setLineWidth(0.5)
canvas.line(0, 0, 7.0*inch, 0) #***
def go():
doc = SimpleDocTemplate("drawline.pdf", pagesize=letter)
doc.leftMargin = 0.25*inch #***
doc.rightMargin = 0.25*inch
doc.topMargin = 0.5*inch
doc.bottomMargin = 0.5*inch
Story = []
style = styles["Normal"]
style.fontName = "Courier"
for i in range(5):
l = DividerLine()
Story.append(l)
doc.build(Story, onFirstPage=myFirstPage, onLaterPages=myLaterPages)
go()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: drawline.pdf
Type: application/pdf
Size: 2172 bytes
Desc: not available
Url : http://two.pairlist.net/pipermail/reportlab-users/attachments/20070105/4420b6a4/attachment.pdf
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: drawline.py
Url: http://two.pairlist.net/pipermail/reportlab-users/attachments/20070105/4420b6a4/attachment.ksh
More information about the reportlab-users
mailing list