This repository was archived by the owner on Sep 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdf_writer.py
More file actions
137 lines (99 loc) · 3.96 KB
/
pdf_writer.py
File metadata and controls
137 lines (99 loc) · 3.96 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import fpdf
import datetime
import os
from PIL import Image
'''
Taken from
https://github.com/dakota0064/Fluorescent_Robotic_Imager
and adapted for TIFF handling by L.P.
2019
'''
__date__ = "06-07-2022"
class PDF(fpdf.FPDF):
def header(self):
# insert logo
# self.image("util_images/logo.png", x=10, y=6, w=60, h=20)
# position logo on the right
#self.cell(80)
self.set_font("Arial", size=14)
date = datetime.date.today()
self.cell(0, 6, str(date), align="R", ln=1)
# set the font for the header, B=Bold
self.set_font("Arial", style="B", size=20)
# page title
self.cell(0, 30, "Crystallization Report", border=0, ln=0, align="C")
# insert a line break of 20 pixels
self.ln(20)
#----------------------------------------------------------------------------
def footer(self):
# position footer at 15mm from the bottom
self.set_y(-15)
# set the font, I=italic
self.set_font("Arial", style="I", size=8)
# display the page number and center it
pageNum = "Page %s/{nb}" % self.page_no()
self.cell(0, 10, pageNum, align="C")
#-----------------------------------------------------------------------------
def create_pdf(_list):
unsupported=[".tif",".tiff",".TIFF", ".TIF"]
TIFFFILE=False
well = _list[0]
well_image = _list[1]
project_name = _list[2]
target_name = _list[3]
plate_name = _list[4]
date = _list[5]
if _list[6]=="None":
prepdate="Not available"
else:
prepdate=_list[6]
d0=datetime.date(int(prepdate[0:4]), int(prepdate[4:6]), int(prepdate[6:]))
d1=datetime.date(int(date[0:4]), int(date[4:6]), int(date[6:]))
delta = d1 - d0
prepdate="%s-%s-%s"%(prepdate[0:4], prepdate[4:6], prepdate[6:])
outputpath=_list[7]
notes = _list[8]
# print("TIF EXT ", os.path.splitext(os.path.basename(well_image))[1])
# print("IMAGE PATH", well_image)
# print("OUTPUT JPEG ", os.path.dirname(well_image)+"/"+os.path.splitext(os.path.basename(well_image))[0]+".jpeg")
if os.path.splitext(os.path.basename(well_image))[1] in unsupported:
img = Image.open(well_image)
rgb_img = img.convert('RGB')
path=os.path.dirname(well_image)+"/"+os.path.splitext(os.path.basename(well_image))[0]
rgb_img.save(path + ".jpeg",'jpeg')
well_image=path + ".jpeg"
TIFFFILE=True
pdf = PDF('P','mm','A4')
pdf.alias_nb_pages()
pdf.add_page()
pdf.set_font("Arial", size=14)
pdf.cell(0, 15, "Well: " + well, align="C", ln=1)
pdf.image(well_image, 52, 50, w=105, h=80)
pdf.ln(90)
pdf.set_font("Arial", style="B", size=12)
pdf.cell(50, 0, "Project name: ", align="R", ln=0)
pdf.set_font("Arial", size=12)
pdf.cell(0, 0, project_name, align="L", ln=1)
pdf.set_font("Arial", style="B", size=12)
pdf.cell(50, 18, "Target name: ", align="R", ln=0)
pdf.set_font("Arial", size=12)
pdf.cell(0, 18, target_name, align="L", ln=1)
pdf.set_font("Arial", style="B", size=12)
pdf.cell(50, 0, "Plate name: ", align="R", ln=0)
pdf.set_font("Arial", size=12)
pdf.cell(0, 0, plate_name, align="L", ln=1)
pdf.set_font("Arial", style="B", size=12)
pdf.cell(50, 18, "Date of image: ", align="R", ln=0)
pdf.set_font("Arial", size=12)
if prepdate=="Not available":
pdf.cell(0, 18, "%s-%s-%s (Preparation date: %s)"%(date[0:4], date[4:6], date[6:], prepdate), align="L", ln=1)
else:
pdf.cell(0, 18, "%s-%s-%s (Preparation date: %s, Number of days: %s)"%(date[0:4], date[4:6], date[6:], prepdate, delta.days), align="L", ln=1)
pdf.ln(2)
pdf.set_font("Arial", size=12, style="B")
pdf.cell(50, 0, "Notes: ", align="R", ln=0)
pdf.set_font("Arial", size=10)
pdf.multi_cell(120, 5, notes, 'J')
pdf.output(outputpath)
if TIFFFILE==True and os.path.exists(path + ".jpeg"):
os.remove(path + ".jpeg")