Я знаю, что есть ответы на этот вопрос, но выслушайте меня.
В настоящее время я пытаюсь сделать PDF из файлов .jpg, используя img2pdf
в python, но вместо добавления файлов в 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
Есть причина для этого? Есть ли особый атрибут, который мне нужно передать?
Любая помощь приветствуется. Спасибо