def framePage(canvas, title): global closeit titlelist.append(title) # canvas._inPage0() # do we need this at all? would be good to eliminate it canvas.saveState() canvas.setFont("Times-BoldItalic", 20) 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 canvas.setFont("Times-Roman", 10) canvas.drawCentredString(4.135 * inch, 0.75 * inch, "Page %d" % canvas.getPageNumber()) canvas.restoreState() canvas.doForm("frame")
def framePage(canvas, title): global closeit titlelist.append(title) #canvas._inPage0() # do we need this at all? would be good to eliminate it canvas.saveState() canvas.setFont('Times-BoldItalic', 20) 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 canvas.setFont('Times-Roman', 10) canvas.drawCentredString(4.135 * inch, 0.75 * inch, 'Page %d' % canvas.getPageNumber()) canvas.restoreState() canvas.doForm("frame")
def draw(self, pmlOp, pageNr, canvas, pe): # we need to adjust y position since PDF uses baseline of text as # the y pos, but pml uses top of the text as y pos. The Adobe # standard Courier family font metrics give 157 units in 1/1000 # point units as the Descender value, thus giving (1000 - 157) = # 843 units from baseline to top of text. # http://partners.adobe.com/asn/tech/type/ftechnotes.jsp contains # the "Font Metrics for PDF Core 14 Fonts" document. x = pe.x(pmlOp.x) y = pe.y(pmlOp.y) - 0.843 * pmlOp.size if pe.doc.tocs and pmlOp.toc: key = "id%d" % id(pmlOp) canvas.bookmarkPage(key, fit="XYZ", left=pe.x(pmlOp.x), top=pe.y(pmlOp.y)) canvas.addOutlineEntry(pmlOp.toc.text, key) newFont = (pe.getFontNr(pmlOp.flags), pmlOp.size) if newFont != pe.currentFont: canvas.setFont(*newFont) pe.currentFont = newFont if pmlOp.angle is None or pmlOp.angle == 0.0: canvas.drawString(x, y, pmlOp.text) else: canvas.saveState() canvas.translate(x, y) canvas.rotate(pmlOp.angle) canvas.drawString(0, 0, pmlOp.text) canvas.restoreState() if pmlOp.flags & pml.UNDERLINED: undLen = fontinfo.getMetrics(pmlOp.flags).getTextWidth( pmlOp.text, pmlOp.size) # all standard PDF fonts have the underline line 100 units # below baseline with a thickness of 50 undY = y - 0.1 * pmlOp.size canvas.setLineWidth(0.05 * pmlOp.size) canvas.line(x, undY, x + undLen, undY)
def draw(self, pmlOp, pageNr, canvas, pe): # we need to adjust y position since PDF uses baseline of text as # the y pos, but pml uses top of the text as y pos. The Adobe # standard Courier family font metrics give 157 units in 1/1000 # point units as the Descender value, thus giving (1000 - 157) = # 843 units from baseline to top of text. # http://partners.adobe.com/asn/tech/type/ftechnotes.jsp contains # the "Font Metrics for PDF Core 14 Fonts" document. x = pe.x(pmlOp.x) y = pe.y(pmlOp.y) - 0.843 * pmlOp.size if pe.doc.tocs and pmlOp.toc: key = "id%d" % id(pmlOp) canvas.bookmarkPage(key,fit="XYZ",left=pe.x(pmlOp.x),top=pe.y(pmlOp.y)) canvas.addOutlineEntry(pmlOp.toc.text,key) newFont = (pe.getFontNr(pmlOp.flags), pmlOp.size) if newFont != pe.currentFont: canvas.setFont(*newFont) pe.currentFont = newFont if pmlOp.angle is None or pmlOp.angle == 0.0: canvas.drawString(x,y,pmlOp.text) else: canvas.saveState() canvas.translate(x,y) canvas.rotate(pmlOp.angle) canvas.drawString(0,0,pmlOp.text) canvas.restoreState() if pmlOp.flags & pml.UNDERLINED: undLen = fontinfo.getMetrics(pmlOp.flags).getTextWidth( pmlOp.text, pmlOp.size) # all standard PDF fonts have the underline line 100 units # below baseline with a thickness of 50 undY = y - 0.1 * pmlOp.size canvas.setLineWidth(0.05 * pmlOp.size) canvas.line(x, undY, x + undLen, undY)
def makesubsection(canvas, title, horizontal): canvas.bookmarkHorizontalAbsolute(title, horizontal) # newsubsection(title) canvas.addOutlineEntry(title + " subsection", title, level=1)
def makesubsection(canvas, title, horizontal): canvas.bookmarkHorizontalAbsolute(title, horizontal) #newsubsection(title) canvas.addOutlineEntry(title + " subsection", title, level=1)
def draw(self): canvas = self.canv for o in self.outlines: canvas.addOutlineEntry(o[0], o[1], o[2], o[3]) canvas.showOutline()