Created
December 20, 2023 15:48
-
-
Save vanatteveldt/0258c29b6be9dc86ca2d33d202630a23 to your computer and use it in GitHub Desktop.
This file contains 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 subprocess | |
from pathlib import Path | |
from PyPDF2 import PdfReader, PdfWriter | |
outPdf=PdfWriter() | |
for inf in Path.cwd().glob("*.html"): | |
pdff = inf.with_suffix(".pdf") | |
if not pdff.exists(): | |
print(f"*1* {inf} -> {pdff}") | |
subprocess.check_call(["wkhtmltopdf", str(inf), str(pdff)]) | |
with open(pdff, 'rb') as input: | |
pdf=PdfReader(input) | |
outPdf.append(pdf) | |
if len(pdf.pages) % 2: | |
outPdf.add_blank_page() | |
outPdf.write("out.pdf") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment