Skip to content

Instantly share code, notes, and snippets.

@saosir
Created May 11, 2018 02:45
Show Gist options
  • Save saosir/e2b7a84d19c4894f0596e621fb1f9e2c to your computer and use it in GitHub Desktop.
Save saosir/e2b7a84d19c4894f0596e621fb1f9e2c to your computer and use it in GitHub Desktop.
合并pdf电子发票到单个文件进行打印
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