-
Notifications
You must be signed in to change notification settings - Fork 0
/
toPDF.py
41 lines (31 loc) · 1.02 KB
/
toPDF.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
import os
import multiprocessing
import numpy as np
path = '/sample_docs'
def WORDtoPDF(in_file):
if in_file.split('.')[-1] in ['doc', 'docx']:
os.system(
f'unoconv --connection \'socket,host=127.0.0.1,port=2220,tcpNoDelay=1;urp;StarOffice.ComponentContext\' -f pdf {path}{in_file}')
os.system(f'rm {path}{in_file}')
func_vect = np.vectorize(WORDtoPDF, otypes=[str])
process = []
def multi_process(file_name):
l = len(file_name)
div = l//4
if div != 0:
for i in range(4):
p = multiprocessing.Process(target=func_vect, args=[
file_name[i*div:(i+1)*div]])
p.start()
process.append(p)
if (l-4*div) != 0:
multi_process(file_name[4*div:l])
else:
p = multiprocessing.Process(target=func_vect, args=[file_name])
p.start()
process.append(p)
def main():
file_names = np.array(os.listdir(path))
multi_process(file_names)
if __name__ == "__main__":
main()