我知道关于这个问题的答案,但是请听我说。
我目前正在尝试使用python中的img2pdf
从.jpg文件中提取PDF,但是没有将文件附加到PDF,而是覆盖了PDF中已经存在的页面。
这是代码
import os,img2pdf
os.chdir("/home/aditya/Desktop")#images are inside desktop
root, dir, files = list(os.walk(os.getcwd()))[0]#files contains the
list of all names of all .jpg file
which I want to convert into PDF
with open("pdf_file.pdf","ab") as f:#PDF file is set to append
for img_file in files:
with open(img_file,"rb") as im_file:#read bytes from the image files
f.write(img2pdf.convert(im_file))#this line overwrites the exisiting
pages in the pdf despite the fact that
I have set it to #append
任何原因吗?我需要传递特殊属性吗?
感谢您的帮助。谢谢