-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (39 loc) · 1.92 KB
/
main.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
50
51
# Third party library for creating pdf objects instances of the FPDF class.
from fpdf import FPDF
import pandas as pd
# Creating the pdf object instance. (All the numbers in the styles below except the
# ones of the size will be in mm - milimiter). Besides, canceling the auto page break func.
pdf = FPDF(orientation="portrait", unit="mm", format="A4")
pdf.set_auto_page_break(auto=False, margin=0)
df = pd.read_csv("topics.csv", sep=",")
# Iterating over each row of the csv file
for index, row in df.iterrows():
# Creating\adding a "master" pdf page (with the "add_page()" func which adds page
# to the document and belongs to the FPDF class).
pdf.add_page()
# Creating and setting the header for the master page: font, color, cell and the line underneath.
pdf.set_font(family="Times", style="B", size=24)
pdf.set_text_color(100, 100, 100)
pdf.cell(w=0, h=12, txt=row["Topic"], align="L", ln=1)
# Creating empty lines from header to footer for the master page.
for y in range(20, 298, 10):
pdf.line(10, y, 200, y)
# Creating and setting the footer for the master page: Breaking lines from the header - "ln()" func,
# font, color and cell.
pdf.ln(265)
pdf.set_font(family="Times", style="I", size=8)
pdf.set_text_color(180, 180, 180)
pdf.cell(w=0, h=10, txt=row["Topic"], align="R")
# Creating the requested num of pages for each topic.
for page in range(row["Pages"] - 1):
pdf.add_page()
# Creating and setting the footer for each other page: break lines, font, color and cell.
pdf.ln(277)
pdf.set_font(family="Times", style="I", size=8)
pdf.set_text_color(180, 180, 180)
pdf.cell(w=0, h=10, txt=row["Topic"], align="R")
# Creating empty lines from header to footer for each other page.
for y in range(20, 298, 10):
pdf.line(10, y, 200, y)
# Generating the pdf file on the disk.
pdf.output("output.pdf")