安装poppler https://wenku.csdn.net/answer/1zxh8ckp6i文章来源地址https://www.toymoban.com/news/detail-740382.html
from pdf2image import convert_from_path, convert_from_bytes
import os
# https://github.com/Belval/pdf2image
output_folder = './'
dpi_value= 600
pdf_start_page = 1 # pdf显示的第一页
start_page = 237 # 真实页码
prex = '' # 图像前缀
def to_image():
def page_generator():
while True:
yield prex
images = convert_from_path(r'xxx.pdf', dpi=600 ,output_folder=output_folder,
first_page=pdf_start_page,fmt='jpg',thread_count=6 , output_file=page_generator())
# convert_from_path(pdf_path, dpi=200, output_folder=None, first_page=None, last_page=None, fmt='ppm', jpegopt=None, thread_count=1, userpw=None, use_cropbox=False, strict=False, transparent=False, single_file=False, output_file=str(uuid.uuid4()), poppler_path=None, grayscale=False, size=None, paths_only=False, use_pdftocairo=False, timeout=600, hide_attributes=False)
# 结果 prex-237.jpg
def image_rename():
# 文件重命名
global start_page
file_list = os.listdir(output_folder)
for file in file_list:
start_page_str = prex + str(start_page)
path = os.path.join(output_folder, file)
print(os.path.join(output_folder, start_page_str + '.jpg'))
os.rename(path, os.path.join(output_folder, start_page_str + '.jpg'))
start_page = start_page + 1
to_image()
image_rename()
文章来源:https://www.toymoban.com/news/detail-740382.html
到了这里,关于使用pdf2image pdf转图片的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!