我想把多个jpg文件合并到一个pdf里面,但是,我打开pdf 只看到只有一张图片,这个问题难到我了,求帮忙?
我想把多个jpg文件合并到一个pdf里面,但是,我打开pdf 只看到只有一张图片,这个问题难到我了,求帮忙?
定义一个列表 img_list = []
每次请求完把图片添加到列表 img_list.append(jpg_file.content)
最后一次性写入 f.write(img2pdf.convert(img_list))
另外,我的建议是改为并行请求,速度更快
参考代码
from concurrent.futures import ThreadPoolExecutor
def getImg(v):
jpg_url =f'https://qingarchives.npm.edu.tw/index.php?act=Display/loadimg/{resouse}/{v}'
jpg_file = requests.get(jpg_url,cookies=cookies,headers=headers)
return jpg_file.content
with open(f'{dirs}/{page_filename}.pdf','wb') as f:
f.write(img2pdf.convert(*ThreadPoolExecutor(20).map(getImg, dicts_filename.get('page_list'))))
img2pdf