forked from cneryx/semi2019
-
Notifications
You must be signed in to change notification settings - Fork 0
/
img2pdf_generator.py
45 lines (35 loc) · 1.26 KB
/
img2pdf_generator.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
# importing necessary libraries
import img2pdf
import os
import argparse
#set layout
letter = (img2pdf.in_to_pt(11), img2pdf.in_to_pt(8.5))
layout = img2pdf.get_layout_fun(letter)
# with open('tile/test.pdf', "wb") as out_file:
# images = []
# for i in range(0, 31 + 1):
# fname = str(i) + '_1.png'
# images.append(fname)
# print(fname)
# out_file.write(img2pdf.convert(images))
def process_images(min_range, max_range, prefix, suffix, out_file,layout):
images = []
for i in range(min_range, max_range + 1):
fname = prefix + str(i) + suffix
images.append(fname)
out_file.write(img2pdf.convert(images,layout_fun=layout))
with open('tile/img2pdf-2-2.pdf', "wb") as out_file:
process_images(0, 31, 'tile/', '_2.png', out_file,layout)
# directory = 'tile/'
# images=[]
# # images.append(None)
# for filename in os.listdir(directory):
# if filename.endswith('png'):
# images.append(Image.open(directory+filename))
# # with open('tile/test.pdf', 'wb') as f:
# # f.write(img2pdf.convert(images, layout_fun=layout))
# # print(filename)
# images[0].save('tile/test.pdf', save_all = True, quality=100, append_images = images[1:])
# closing pdf file
# output
print("Successfully made pdf file")