def merge(self, final_pdf_path, actions, append_blank_page=False):
"""
Merge files (images and pdfs) in to one PDF
:param final_pdf_path: file path to save pdf
:param actions: list of tuples, each tuple consisting of a PDF file path, and the amount of clockwise rotation
to apply to the document.
:param append_blank_page: append a blank page between documents if True.
:return:
"""
real_actions = []
tmp_to_delete_paths = []
for file_path, rotation in actions:
if imghdr.what(file_path):
img = Image.open(file_path)
path = self.image_to_pdf(img)
action = (path, rotation)
real_actions.append(action)
tmp_to_delete_paths.append(path)
else:
action = (file_path, rotation)
real_actions.append(action)
self.merge_pdfs(final_pdf_path, real_actions, append_blank_page)
for path_to_delete in tmp_to_delete_paths:
os.remove(path_to_delete)
评论列表
文章目录