Skip to content

Instantly share code, notes, and snippets.

@Burekasim
Created August 10, 2022 12:26
Show Gist options
  • Save Burekasim/cb9686195ebd4e047f62b835770a5d40 to your computer and use it in GitHub Desktop.
Save Burekasim/cb9686195ebd4e047f62b835770a5d40 to your computer and use it in GitHub Desktop.
Pdf merger (Regina 2000)
import datetime
from PyPDF2 import PdfFileMerger
import os
def get_pdf_files_from_current_folder(current_folder: str):
output_list = []
for item in os.listdir(current_folder):
if item.endswith('.pdf'):
output_list.append(item)
return sorted(output_list)
if __name__ == '__main__':
folder = os.getcwd()
pdfs = get_pdf_files_from_current_folder(folder)
os.chdir(folder)
merger = PdfFileMerger()
for pdf in pdfs:
merger.append(pdf)
current_time = datetime.datetime.now().strftime('%H%M%S')
merger.write(f'{current_time}-regina2000.pdf')
merger.close()
@Burekasim
Copy link
Author

@Burekasim
Copy link
Author

I've updated the repo with natural sort instead of the sorted function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment