Source code for pdf.page_functions

from datetime import date
from lxml import etree
from textwrap import shorten
from textwrap import wrap


from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from onegov.pdf.templates import Template
    from reportlab.pdfgen.canvas import Canvas


[docs] def empty_page_fn(canvas: 'Canvas', doc: 'Template') -> None: """ An empty header/footer. """
[docs] def page_fn_header(canvas: 'Canvas', doc: 'Template') -> None: """ A standard header consisting of a title and the creation string. The title is automatically wrapped and shortened. Example:: pdf = Pdf(file, author='OneGov', created='1.1.2000') pdf.init_a4_portrait(page_fn=page_fn_header) """ canvas.saveState() canvas.setFont('Helvetica', 9) if doc.title: lines = wrap(doc.title, 110)[:2] if len(lines) > 1: lines[1] = shorten(lines[1], 100) text = canvas.beginText() text.setTextOrigin( doc.leftMargin, doc.pagesize[1] - doc.topMargin * 2 / 3 ) text.textLines(lines) canvas.drawText(text) if created := getattr(doc, 'created', None): canvas.drawRightString( doc.pagesize[0] - doc.rightMargin, doc.pagesize[1] - doc.topMargin * 2 / 3, created ) canvas.restoreState()