Skip to content

Commit 20194f8

Browse files
committed
changing pdf printing to use built-in selenium print to pdf functionality
1 parent 4ae07f9 commit 20194f8

File tree

3 files changed

+7
-25
lines changed

3 files changed

+7
-25
lines changed

visokio-omniprint/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "visokio-omniprint"
7-
version = "1.1.7"
7+
version = "1.2.0"
88
description = "Visokio Omniscope PDF printing library"
99
readme = "README.md"
1010
requires-python = ">=3.7"
@@ -25,7 +25,7 @@ classifiers = [
2525
"Programming Language :: Python :: Implementation :: PyPy",
2626
]
2727
dependencies = [
28-
"selenium",
28+
"selenium>=4.26.0",
2929
"webdriver-manager",
3030
"get-chrome-driver>=1.3.19",
3131
"tinify",

visokio-omniprint/visokio_omniprint/DriverBase.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,6 @@ def get_driver(self, is_docker):
7373
return self.get_driver_host(options)
7474

7575

76-
def send_devtools(self, driver, cmd, params):
77-
"""
78-
This function sends a command to the Chrome DevTools API and returns the result.
79-
"""
80-
resource = "/session/%s/chromium/send_command_and_get_result" % driver.session_id
81-
url = driver.command_executor._url + resource
82-
body = json.dumps({"cmd": cmd, "params": params})
83-
response = driver.command_executor._request("POST", url, body)
84-
85-
if not response:
86-
raise Exception(response.get("value"))
87-
88-
return response.get("value")
89-
90-
9176
def get_driver_for_url(self, url, timeout, is_docker):
9277
driver = self.get_driver(is_docker)
9378
driver.get(url) # Navigate to the specified URL

visokio-omniprint/visokio_omniprint/Pdf.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import base64
3+
from selenium.webdriver.common.print_page_options import PrintOptions
34

45
from .DriverBase import DriverBase
56

@@ -9,17 +10,13 @@ def create_pdf(self, url, timeout, is_docker):
910

1011
driver = self.get_driver_for_url(url, timeout, is_docker)
1112

12-
print_options = {
13-
"landscape": False,
14-
"displayHeaderFooter": False,
15-
"printBackground": True,
16-
"preferCSSPageSize": True,
17-
}
13+
print_options = PrintOptions()
14+
print_options.orientation = "portrait"
1815

19-
result = self.send_devtools(driver, "Page.printToPDF", print_options)
16+
result = driver.print_page(print_options)
2017
driver.get("about:blank") # Navigate away to ensure page is unloaded properly.
2118
driver.quit()
22-
return base64.b64decode(result["data"])
19+
return base64.b64decode(result)
2320

2421

2522
def write_pdf_to_path(self, path, pdf):

0 commit comments

Comments
 (0)