-
Notifications
You must be signed in to change notification settings - Fork 4
/
footer.py
36 lines (29 loc) · 1.15 KB
/
footer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from reportlab.pdfgen import canvas
class FooterCanvas(canvas.Canvas):
def __init__(self, *args, is_booklet=False, font_name='Times-Roman', **kwargs):
super().__init__(*args, **kwargs)
self.is_booklet = is_booklet
self.font_name = font_name
self.previous_bottom = 0
def showPage(self):
self.draw_canvas()
super().showPage()
def draw_canvas(self):
x = 30
width, height = self._pagesize
template = getattr(self, '_doctemplate', None)
if template is None:
bottom = self.previous_bottom
else:
bottom = self.previous_bottom = template.bottomMargin
self.saveState()
self.setFont(self.font_name, 8 if self.is_booklet else 9)
if self._pageNumber % 2:
self.drawRightString(width-x, bottom, str(self._pageNumber))
else:
self.drawString(x, bottom, str(self._pageNumber))
if self._pageNumber == 1:
self.drawCentredString(width / 2,
bottom,
"https://donkirkby.github.io/donimoes")
self.restoreState()