Fork me on GitHub

PDF转Img

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
from wand.image import Image
import os

def convert_pdf_to_jpg(filePath,filename):
with Image(filename=filePath, resolution=150) as img :
with img.convert('jpeg') as converted:
fileNa = 'image/' + filename + '.jpeg'
print(fileNa)
converted.save(filename=fileNa)

def findPDFs(f,s,pdfs,files):

fs = os.listdir(f)
for f1 in fs:
tmp_path = os.path.join(f,f1)
if not os.path.isdir(tmp_path):
if s in os.path.splitext(f1)[1]:
files.append(f1[:-4])
pdfs.append(tmp_path)
else:
findPDFs(tmp_path, s, pdfs, files)

# for pdf in pdfs:
# convert_pdf_to_jpg(pdf)

def pdfToImg(pdfPaths, names):
if len(pdfPaths) == len(names):
for i in range(0,len(pdfPaths)):
convert_pdf_to_jpg(pdfPaths[i], names[i])
pass

pdfs = []
files = []
path = os.getcwd()
findPDFs(path,"pdf",pdfs,files)
pdfToImg(pdfs,files)
-------------本文结束感谢您的阅读-------------

本文作者:乔羽 / FightingJoey

发布时间:2018年09月26日 - 21:56

最后更新:2019年01月15日 - 19:37

原始链接:https://fightingjoey.github.io/2018/09/26/记录/PDF转Img/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

坚持原创技术分享,您的支持将鼓励我继续创作!