pdf.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:document_clipper 作者: reclamador 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号