-
Notifications
You must be signed in to change notification settings - Fork 2
/
print.py
49 lines (35 loc) · 1.32 KB
/
print.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /usr/bin/env python3
import base64
import time
import frontmatter
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
options = Options()
options.add_argument("--window-size=1920,1200")
options.add_argument("--headless")
driver = webdriver.Chrome(
service=Service(ChromeDriverManager().install()), options=options
)
with open("src/content/header.md") as f:
header = frontmatter.load(f)
firstname = header.metadata.get("firstname", "").lower()
lastname = header.metadata.get("lastname", "").lower()
cv_filename = f"{firstname}{lastname}-curriculumvitae.pdf"
cl_filename = f"{firstname}{lastname}-coverletter.pdf"
driver.get("http://localhost:9000")
time.sleep(3)
cvpdf = driver.execute_cdp_cmd(
"Page.printToPDF", {"printBackground": False, "displayHeaderFooter": False}
)
with open(cv_filename, "wb") as f:
f.write(base64.b64decode(cvpdf["data"]))
driver.find_element(value="button-cl").click()
clpdf = driver.execute_cdp_cmd(
"Page.printToPDF", {"printBackground": False, "displayHeaderFooter": False}
)
with open(cl_filename, "wb") as f:
f.write(base64.b64decode(clpdf["data"]))
driver.quit()