-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathheader_footer.py
49 lines (37 loc) · 1.37 KB
/
header_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
37
38
39
40
41
42
43
44
45
46
47
48
49
from fpdf import FPDF
# Author: @NavonilDas
class MyPdf(FPDF):
def header(self):
# Uncomment the line below to add logo if needed
# self.image('somelogo.png',12,10,25,25) # Draw Image ar (12,10) with height = 25 and width = 25
self.set_font("Arial", "B", 18)
self.text(27, 10, "Generating PDF With python")
self.ln(10)
def footer(self):
# Set Position at 1cm (10mm) From Bottom
self.set_y(-10)
# Arial italic 8
self.set_font("Arial", "I", 8)
# set Page number at the bottom
self.cell(0, 10, "Page No {}".format(self.page_no()), 0, 0, "C")
pass
pdf = MyPdf()
# Set Author Name of the PDF
pdf.set_author("@NavonilDas")
# Set Subject of The PDF
pdf.set_subject("python")
# Set the Title of the PDF
pdf.set_title("Generating PDF with Python")
pdf.add_page()
# Set Font family Courier with font size 28
pdf.set_font("Courier", "", 18)
# Add Text at (0,50)
pdf.text(0, 50, "Example to generate PDF in python.")
# Set Font Family Courier with italic and font size 28
pdf.set_font("Courier", "i", 28)
pdf.text(0, 60, "This is an italic text") # Write text at 0,60
pdf.add_page()
# Center Text With border and a line break with height=10mm
pdf.cell(0, 10, "Hello There", 1, 1, "C")
# Save the Output at Local File
pdf.output("output.pdf", "F")