-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf.py
36 lines (26 loc) · 835 Bytes
/
pdf.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
from fpdf import FPDF
class PDF(FPDF):
def footer(self):
# Position at 1.5 cm from bottom
self.set_y(-15)
# Arial italic 8
self.set_font('Arial', 'I', 8)
# Text color in gray
self.set_text_color(128)
# Page number
self.cell(0, 10, 'Page ' + str(self.page_no()), 0, 0, 'C')
def chapter_body(self, name):
# Read text file
with open(name, 'rb') as fh:
txt = fh.read().decode('latin-1')
# Times 12
self.set_font('Arial', '', 14)
# Output justified text
self.multi_cell(0, 5, txt)
# Line break
self.ln()
# Mention in italics
self.set_font('', 'I')
def print_chapter(self, num, title, name):
self.add_page()
self.chapter_body(name)