diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d1616bd --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +front/* +back/* +out/* +*.pdf +.vscode/settings.json diff --git a/combine.py b/combine.py new file mode 100644 index 0000000..5aa3f1f --- /dev/null +++ b/combine.py @@ -0,0 +1,31 @@ +import os +import glob + + +def get_ordered_files(dir_name): + # Get list of all files only in the given directory + list_of_files = filter(os.path.isfile, glob.glob(dir_name + '/*')) + + # Sort list of files based on creation time in ascending order + list_of_files = sorted(list_of_files, key=os.path.getctime) + + return list_of_files + +def site(path, out, reversed): + + f = get_ordered_files(path) + if reversed: + f = f[::-1] + f = [f'"{s}"' for s in f] + s = ' '.join(f) + exec_string = f"img2pdf {s} -o {out}" + return exec_string + + +front_out = "out/front.pdf" +back_out = "out/back.pdf" +merged_out = "out/merged.pdf" + +os.system(site("./front", front_out, False)) +os.system(site("./back", back_out, True)) +os.system(f"pdftk A={front_out} B={back_out} shuffle A B output {merged_out}") diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8be1c41 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +img2pdf \ No newline at end of file