def addTitle(self, para=u"Minimal Example Title", outTemplate='LaterL'): """ # add title """ para = ar.Paragraph(para, self.styles.title) self.contents.append(para) outTemplate = self.doc.getTemplate(temp_name=outTemplate) ar.PageNext(self.contents, nextTemplate=outTemplate) self.contents.append(ar.PageBreak())
def addToc(self, para=u"Inhaltsverzeichnis"): """ # add table of contents # Create an instance of TableOfContents. # Override the level styles (optional) # and add the object to the story """ toc = ar.doTabelOfContents() self.contents.append(ar.Paragraph(para, self.styles.h1)) self.contents.append(toc) self.contents.append(ar.PageBreak())
def addChapter(self, para="Text", nextTemplate='LaterL', sty=None): """ # add chapter """ # default style h1 if sty is None: sty = self.styles.h1 nextTemplate = self.doc.getTemplate(temp_name=nextTemplate) ar.PageNext(self.contents, nextTemplate=nextTemplate) # Begin of First Chapter self.contents.append(ar.PageBreak()) part = ar.doHeading(para, sty) for p in part: self.contents.append(p)
def _apply_page(self, page, content, chapter, pageState, deep=False): """ not used from outside, only internal use! """ if "chapter-bookmark" in page: chapter = page["chapter-bookmark"] return content, chapter, pageState if page["framestyle"] == "double": if chapter: content.append(chapter) frameInfo, _ = self.doc.getFrame( self.laterFrames[self.orientation]) # NOTE how to make sure next page is a double page ?? content.extend(page["content"]["left"]) content.append(ar.FrameBreak()) content.extend(page["content"]["right"]) content.append(ar.FrameBreak()) #content.append(page["content"]["top"]) #content.append(page["content"]["bottom"]) # frameWidth = frameInfo._aW - (frameInfo._x1 * 2.) # print("frameWidth:", frameWidth) marginSide = self.doc.leftMargin + self.doc.rightMargin content.append(page["bookmark"]) content.append(page["header"].margin_top) content.append(page["header"].layoutFullWidthTable( frameInfo, marginSide=marginSide)) headerHeight = page["header"].height(frameInfo) content.append(page["footer"].margin_top(frameInfo, headerHeight)) content.append(page["footer"].layoutFullWidthTable( frameInfo, marginSide=marginSide, ratios=[0.3, 0.2, 0.2, 0.3])) content.append(ar.PageBreak()) pageState = "double" nextPage = None elif page["framestyle"] == "single": if pageState == "double" or pageState == "later": # content.append(self.doc.getSpecialTemplate()) # was LaterSL content = ar.PageNext( content, self.doc.getSpecialTemplate(temp_name="Later")) frameInfo, _ = self.doc.getFrame( self.laterFrames[self.orientation], last=True) else: frameInfo, _ = self.doc.getFrame( self.laterFrames[self.orientation]) if chapter: content.append(chapter) content.append(page["content"]["top"]) # NOTE the possibility of tables flowing onto next page # is only provided on single pages flowable, nextPage = self.ensure_flowables( frameInfo, page["content"]["center"], page) content.extend(flowable) content.append(page["content"]["bottom"]) content.append(ar.FrameBreak()) if not deep: content.append(page["bookmark"]) marginSide = self.doc.leftMargin + self.doc.rightMargin content.append(page["header"].margin_top) content.append(page["header"].layoutFullWidthTable( frameInfo, marginSide=marginSide)) headerHeight = page["header"].height(frameInfo) content.append(page["footer"].margin_top(frameInfo, headerHeight)) content.append(page["footer"].layoutFullWidthTable( frameInfo, marginSide=marginSide, ratios=[0.3, 0.2, 0.2, 0.3])) content.append(ar.PageBreak()) pageState = "later" else: print("unknown frame style") raise Exception if nextPage: content, chapter, pageState = self._apply_page(nextPage, content, chapter, pageState, deep=True) return content, None, pageState
doc = ar.AutoDocTemplate(outname, onFirstPage=ar.onFirstPage, onLaterPages=ar.onLaterPages, onLaterSPages=ar.onLaterPages, leftMargin=0.5 * ar.cm, rightMargin=0.5 * ar.cm, topMargin=0.5 * ar.cm, bottomMargin=0.5 * ar.cm) content = [] #add title para = ar.Paragraph(u"Minimal Example Title", styles.title) content.append(para) content.append(ar.PageBreak()) # Create Table Of Contents. Override the level styles (optional) # and add the object to the story toc = ar.doTabelOfContents() content.append(ar.Paragraph(u"Inhaltsverzeichnis", styles.h1)) content.append(toc) ## Example 1 adding a table content.append(ar.PageBreak()) ar.addHeading("A Table", styles.h1, content) para = ar.Paragraph( u"My Text that I can write here or take it from somewhere like shown in the next paragraph.", styles.normal) content.append(para)