DaSE-Computer-Vision-2021
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

44 lines
1.1 KiB

import argparse
import os
import subprocess
try:
from PyPDF2 import PdfFileMerger
MERGE = True
except ImportError:
print("Could not find PyPDF2. Leaving pdf files unmerged.")
MERGE = False
def main(files):
os_args = [
"jupyter",
"nbconvert",
"--log-level",
"CRITICAL",
"--to",
"pdf",
]
for f in files:
os_args.append(f)
subprocess.run(os_args)
print("Created PDF {}.".format(f))
if MERGE:
pdfs = [f.split(".")[0] + ".pdf" for f in files]
merger = PdfFileMerger(strict=True)
for pdf in pdfs:
merger.append(pdf)
merger.write("assignment.pdf")
merger.close()
for pdf in pdfs:
os.remove(pdf)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
# we pass in explicit notebook arg so that we can provide
# an ordered list and produce an ordered pdf
parser.add_argument("--notebooks", type=str, nargs="+", required=True)
args = parser.parse_args()
main(args.notebooks)