Example #1
0
 def beforeDrawPage(self, canvas):
     """Draws the background before anything else"""
     canvas.saveState()
     rl_obj = makerl(canvas, self.page_template)
     canvas.scale(self.page_xscale, self.page_yscale)
     canvas.doForm(rl_obj)
     canvas.restoreState()
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")
Example #4
0
markup = "The answer is: $E=\\frac{m_1v^2}{2}$"

markup_tex = """
    \documentclass{standalone}
    \\begin{document}
    %s
    \end{document}
""" % markup

pdflatex = subprocess.Popen(["pdflatex"],
                            stdin=subprocess.PIPE,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
stdout, stderr = pdflatex.communicate(markup_tex)
if pdflatex.returncode:
    print stdout, stderr

canvas = reportlab.pdfgen.canvas.Canvas("latex-math-pdf.pdf")

for page in pdfrw.PdfReader("texput.pdf").pages:
    page = pdfrw.buildxobj.pagexobj(page)

    canvas.saveState()
    canvas.translate(100, 100)
    canvas.doForm(pdfrw.toreportlab.makerl(canvas, page))
    canvas.restoreState()

canvas.showPage()
canvas.save()
Example #5
0
markup = "The answer is: $E=\\frac{m_1v^2}{2}$"

markup_tex = (
    """
    \documentclass{standalone}
    \\begin{document}
    %s
    \end{document}
"""
    % markup
)

pdflatex = subprocess.Popen(["pdflatex"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = pdflatex.communicate(markup_tex)
if pdflatex.returncode:
    print stdout, stderr

canvas = reportlab.pdfgen.canvas.Canvas("latex-math-pdf.pdf")

for page in pdfrw.PdfReader("texput.pdf").pages:
    page = pdfrw.buildxobj.pagexobj(page)

    canvas.saveState()
    canvas.translate(100, 100)
    canvas.doForm(pdfrw.toreportlab.makerl(canvas, page))
    canvas.restoreState()

canvas.showPage()
canvas.save()