-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf2zip2ppt.py
64 lines (40 loc) · 1.69 KB
/
pdf2zip2ppt.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
import os
import subprocess
import re
import zipfile
import shutil
pattern_list = ['MV_']
for file_pattern in pattern_list:
dir_zip = 'zip'
dir_pdf = 'pdf'
dir_png = 'png'
density = '500'
dir_base = "C:/project/Occasional/20240910_liver_paper/_figs/draft"
path_zip=dir_base + '/'+file_pattern+'.zip'
with zipfile.ZipFile(path_zip, 'w') as zip_ref:
# convert to zip
for file_base in os.listdir(dir_base):
if re.search(".pdf", file_base):
if re.search(file_pattern, file_base):
zip_ref.write(os.path.join(dir_base, file_base), file_base)
print('File created: '+ path_zip + '\n')
# drop PDF and PNG here
for file_base in os.listdir(dir_pdf):
if re.search(".pdf", file_base):
file_path = os.path.join(dir_pdf, file_base)
os.remove(file_path)
for file_base in os.listdir(dir_png):
if re.search(".png", file_base):
file_path = os.path.join(dir_png, file_base)
os.remove(file_path)
with zipfile.ZipFile(path_zip, 'r') as zip_ref:
zip_ref.extractall(dir_pdf)
for file_base in os.listdir(dir_pdf):
if re.search(".pdf", file_base):
file_png = file_base.replace(".pdf", ".png")
path_base = os.path.join(dir_base, file_base)
path_png = os.path.join(dir_png, file_png)
subprocess.call(['magick','-density', density, path_base,'-resize', '100%', '-compress','lzw', '-background','white', '-alpha','remove', path_png], shell=True)
print(file_png)
file_pptx = dir_base + "/" + file_pattern
subprocess.call(['node','pdf2ppt.js', file_pptx], shell=True)