=if(d3 = "PS124", c3, "")
如您所见,这将创建TOC以及FooterCanvas类的页眉和页脚,而FooterCanvas类将应用于所有页面,但我不希望将其应用于我的pdf的首页。那我该如何实现呢?
答案 0 :(得分:1)
看起来您只有一个PageTemplate。当我想要类似的控件时,我将创建两个单独的PageTemplates,如下所示。
background-size: cover
答案 1 :(得分:1)
在其他答案的帮助下,我找到了另一种方法。所以就在这里。
Frame1=Frame(x1,y1,width,height,id='F1')
Frame2=Frame(x1,y1,width,height,id='F2')
def FooterCanvas(canvas,doc):
page = "Page %s" % (canvas._pageNumber)
canvas.saveState()
canvas.setFont('Times-Roman', 10)
canvas.drawString(280, 15, page)
canvas.restoreState()
class MyDocTemplate(BaseDocTemplate):
def __init__(self, filename, **kw):
self.allowSplitting = 0
apply(BaseDocTemplate.__init__, (self, filename), kw)
self.addPageTemplates([PageTemplate(id='firstPage',frames=Frame1),PageTemplate(id='allpages',frames=Frame2,onPage=FooterCanvas)
])
def afterFlowable(self, flowable):
if flowable.__class__.__name__ == 'Paragraph':
text = flowable.getPlainText()
style = flowable.style.name
if style == 'Heading1':
self.notify('TOCEntry', (0, text, self.page))
if style == 'Heading2':
self.notify('TOCEntry', (1, text, self.page))
Story=[]
write your styles here and write your TOC styles. create TOC instance and add levels for TOC(levels are optional).
Story.append(NextPageTemplate('firstpage'))
First page with some paragraph or graphics.
Story.append(NextPageTemplate('allpages'))
Story.append(PageBreak())
Rest of the pages with some paragraph or graphics.
doc=MyDocTemplate("abc.pdf")
doc.multiBuild(Story)