Created
May 11, 2018 02:45
-
-
Save saosir/e2b7a84d19c4894f0596e621fb1f9e2c to your computer and use it in GitHub Desktop.
合并pdf电子发票到单个文件进行打印
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from PyPDF2 import PdfFileMerger | |
pdf_dir = r"E:\note\invoice" | |
def merge_pdf(source_dir, output_filename): | |
merger = PdfFileMerger() | |
for name in os.listdir(source_dir): | |
if ".pdf" != os.path.splitext(name)[1]: | |
continue | |
filename = os.path.join(source_dir, name) | |
print filename | |
with open(filename, "rb") as input: | |
merger.append(input) | |
with open(output_filename, "wb") as output: | |
merger.write(output) | |
if __name__ == '__main__': | |
merge_pdf(pdf_dir, "d:/merge.pdf") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment