-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcc_pdfbuilder.py
80 lines (69 loc) · 2.7 KB
/
cc_pdfbuilder.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from fpdf import FPDF
from datetime import datetime
# Certain parts of the code taken from the documentation:
# https://pyfpdf.readthedocs.io/en/latest/Tutorial/index.html
class PDF_REPORT(FPDF):
def header(self):
self.image('assets/logo.png', 76, 11, 8, link='https://github.com/BenSt099/CitationCheck')
self.set_font('Times', 'B', 15)
self.cell(80)
self.cell(30, 10, 'CitationCheck', 0, 0, 'C')
self.ln(20)
def footer(self):
self.set_y(-15)
self.set_font('Arial', 'I', 8)
self.cell(0, 10, 'Page ' + str(self.page_no()) + '/{nb}', 0, 0, 'C')
def cc_build_and_save_pdf(filename, data):
# data = [
# [entry1],[entry2],[entry3]
#]
# [entry1] = [Title, DOI, [Reasons]]
filename = filename + ".pdf"
pdf = PDF_REPORT()
pdf.alias_nb_pages()
pdf.add_page()
pdf.set_font('Times', '', 12)
for i in range(0,len(data)):
pdf.set_font('Times', 'B', 16)
pdf.set_text_color(222, 53, 65)
list_of_lines = format_title(data[i][0])
for line in list_of_lines:
pdf.cell(0, 7, line, 0, 1)
pdf.set_font('Times', '', 12)
pdf.set_text_color(0,0,0)
pdf.set_font('Times', 'B', 12)
pdf.cell(16, 6, 'DOI: ', 0, 0)
pdf.set_font('Times', '', 12)
pdf.cell(0, 6, data[i][1], 0, 1)
list_of_reasons = format_reasons(data[i][2])
for reason in list_of_reasons:
reason = reason.strip()
if reason != '':
pdf.cell(20)
pdf.cell(0, 6, reason, 0, 1)
pdf.cell(0, 6, '', 0, 1)
pdf.cell(0, 6, '', 0, 1)
pdf.set_font('Times', 'I', 8)
pdf.cell(0, 5, r"This report was generated by 'CitationCheck' (LINK: https://github.com/BenSt099/CitationCheck) on " + str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), 0, 1, 'C')
pdf.cell(0, 5, 'It comes WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.', 0, 1, 'C')
pdf.cell(0, 5, r"The program 'CitationCheck' is licensed under GNU GENERAL PUBLIC LICENSE (Version 3, 29 June 2007).", 0, 1, 'C')
pdf.output(filename, 'F')
def format_title(title):
# MAX = 63 characters
title_list = []
oneline = ''
if len(title) <= 63:
title_list.append(title)
return title_list
sections = title.split(' ')
for word in sections:
if len(oneline) + len(word) <= 63:
oneline = oneline + word + ' '
else:
title_list.append(oneline.strip())
oneline = '' + word + ' '
if oneline.strip() != '':
title_list.append(oneline.strip())
return title_list
def format_reasons(reasons):
return reasons.split(';')