PDF文件合并

 2年前     244  

文章目录

    工作后经常报销,开的发票都是单个PDF文件,windows自带EDGE浏览器无法合并打印,导致每次打印的发票文件都是一整张A4纸(太大了),所以需要将PDF文件合并在同一个PDF文件中,然后再选择每张纸打印多页的功能。于是查阅资料后使用Python写了一个PDF合并的软件。

    PDF文件合并

    D盘创建发票的目录,并将PDF发票放在此目录下,然后运行该软件(源码),几秒钟后当前目录的所有的以.pdf为后缀的文件被合并成“发票合并.pdf”文件,在打印时就可以选择每张纸打印几张发票了。

    PDF文件合并

    源码运行前需提前安装PyPDF2库(使用软件无需安装),安装命令如下:

    pip install PyPDF2

    附上源码:

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    import os
    from PyPDF2 import PdfFileMerger
    
    # Specify the directory where the PDF files are located
    
    directory = "D:\\发票\\"
    
    # Create a PdfFileMerger object
    merger = PdfFileMerger()
    
    # Loop through all PDF files in the directory
    for filename in os.listdir(directory):
        # Check if the file is a PDF file
        if filename.endswith(".pdf"):
            # Join the file path with the directory path
            filepath = os.path.join(directory, filename)
            # Append the file to the merger object
            merger.append(filepath)
    
    # Write the merged PDF file to a new file
    merger.write("D:\\发票\\发票合并.pdf")
    
    
    # 打包命令
    # pyinstaller -F -w -i t.ico PDF合并.py

     

    下载信息资源名称:PDF合并软件应用平台:windows文件下载:7 次下载地址
    【腾讯云】2核2G4M云服务器新老同享99元/年,续费同价
    版权声明:ADMIN 发表于 2年前,共 835 字。
    转载请注明:PDF文件合并 | 奎利