[reportlab-users] Passing canvas of SimpleDocTemplate as argument
Rasha Ebo
rshzky at yahoo.com
Thu Mar 9 04:15:04 EST 2006
I make pdf files using the 'SimpleDocTemplate', and I want to make bookmarks to link to the content of the pdf pages.
The following function is the function that sets the layout of every pdf page and makes the bookmarks and it sould take 5 arguments, beside the canavs and doc arguments, other 3 arguments that are used to supply the title of the bookmarks
def myLaterPages(canvas, doc, title, yGroup , clsName):
global closeit
titlelist.append(title)
pageinfo = yGroup + clsName
canvas.saveState()
canvas.setFont('Courier-Oblique',10)
canvas.drawString(inch, 0.75 * inch, "Page %d %s" % (doc.page, pageinfo))
canvas.drawString(inch, 10.5 * inch, title)
canvas.bookmarkHorizontalAbsolute( title , 10.8*inch)
#newsection(title)
canvas.addOutlineEntry(title +" section", title , level=0, closed=closeit)
closeit = not closeit # close every other one
makesubsection(canvas, "caps and joins", 8.5*inch)
canvas.restoreState()
"""
The following function makes the subsections of bookmarks
def makesubsection(canvas, title, horizontal):
canvas.bookmarkHorizontalAbsolute(title, horizontal)
#newsubsection(title)
canvas.addOutlineEntry(title+" subsection", title, level=1)
The following line creates an instance of the DocTemplate
doc = SimpleDocTemplate("phello.pdf")
The following line builds up the doc and in which I pass the input arguments that are used in the first function 'myLaterPages' which makes up the bookmarks and here comes the problem
doc.build(Story, onFirstPage=myFirstPage, onLaterPages=myLaterPages(canvas, doc=doc, title='rasha', yGroup ='y1', clsName='y1a'))
When I run the code, the following error occurs:
'module' object has no attribute 'saveState'
refering to line 5 in the first function 'myLaterPages'
I do not know how to pass the arguments of 'myLaterPages' in the building line without generating an error and I think the error is with the canvas argument but the problem is that I use 'SimpleDocTemplate' and not normal canvas so I do not know what to pass, Please help
---------------------------------
Brings words and photos together (easily) with
PhotoMail - it's free and works with Yahoo! Mail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://two.pairlist.net/pipermail/reportlab-users/attachments/20060309/cf460df9/attachment.html
More information about the reportlab-users
mailing list