Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- name: Install Google Chrome
run: |
choco install googlechrome --no-progress -y
choco install googlechrome --no-progress -y --ignore-checksums
shell: powershell

- name: Check Chrome Version
Expand Down
34 changes: 17 additions & 17 deletions html2print/html2print.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from webdriver_manager.core.http import HttpClient
from webdriver_manager.core.os_manager import OperationSystemManager

__version__ = "0.0.3"
__version__ = "0.0.5"

DEFAULT_CACHE_DIR = os.path.join(Path.home(), ".html2print", "chromedriver")

Expand All @@ -40,7 +40,7 @@ def get(self, url, params=None, **kwargs) -> Response:
last_error: Optional[Exception] = None
for attempt in range(1, 3):
print( # noqa: T201
f"html2pdf: sending GET request attempt {attempt}: {url}"
f"html2print: sending GET request attempt {attempt}: {url}"
)
try:
return requests.get(url, params, timeout=(5, 5), **kwargs)
Expand All @@ -50,10 +50,10 @@ def get(self, url, params=None, **kwargs) -> Response:
last_error = read_timeout_
except Exception as exception_:
raise AssertionError(
"html2pdf: unknown exception", exception_
"html2print: unknown exception", exception_
) from None
print( # noqa: T201
f"html2pdf: "
f"html2print: "
f"failed to get response for URL: {url} with error: {last_error}"
)

Expand Down Expand Up @@ -83,24 +83,24 @@ def find_driver(self, driver: Driver):
)
if os.path.isfile(path_to_cached_chrome_driver):
print( # noqa: T201
f"html2pdf: ChromeDriver exists in the local cache: "
f"html2print: ChromeDriver exists in the local cache: "
f"{path_to_cached_chrome_driver}"
)
return path_to_cached_chrome_driver
print( # noqa: T201
f"html2pdf: ChromeDriver does not exist in the local cache: "
f"html2print: ChromeDriver does not exist in the local cache: "
f"{path_to_cached_chrome_driver}"
)
path_to_downloaded_chrome_driver = super().find_driver(driver)
if path_to_downloaded_chrome_driver is None:
print( # noqa: T201
f"html2pdf: could not get a downloaded ChromeDriver: "
f"html2print: could not get a downloaded ChromeDriver: "
f"{path_to_cached_chrome_driver}"
)
return None

print( # noqa: T201
f"html2pdf: saving chromedriver to StrictDoc's local cache: "
f"html2print: saving chromedriver to StrictDoc's local cache: "
f"{path_to_downloaded_chrome_driver} -> {path_to_cached_chrome_driver}"
)
Path(path_to_cached_chrome_driver_dir).mkdir(
Expand All @@ -116,7 +116,7 @@ def get_inches_from_millimeters(mm: float) -> float:


def get_pdf_from_html(driver, url) -> bytes:
print(f"html2pdf: opening URL with ChromeDriver: {url}") # noqa: T201
print(f"html2print: opening URL with ChromeDriver: {url}") # noqa: T201

driver.get(url)

Expand Down Expand Up @@ -170,7 +170,7 @@ class Done(Exception):
)
sys.exit(1)

print("html2pdf: JS logs from the print session:") # noqa: T201
print("html2print: JS logs from the print session:") # noqa: T201
print('"""') # noqa: T201
for entry in logs:
print(entry) # noqa: T201
Expand All @@ -179,7 +179,7 @@ class Done(Exception):
#
# Execute Print command with ChromeDriver.
#
print("html2pdf: executing print command with ChromeDriver.") # noqa: T201
print("html2print: executing print command with ChromeDriver.") # noqa: T201
result = driver.execute_cdp_cmd("Page.printToPDF", calculated_print_options)

data = base64.b64decode(result["data"])
Expand All @@ -205,7 +205,7 @@ def create_webdriver(chromedriver: Optional[str], path_to_cache_dir: str):
path_to_chrome = get_chrome_driver(path_to_cache_dir)
else:
path_to_chrome = chromedriver
print(f"html2pdf: ChromeDriver available at path: {path_to_chrome}") # noqa: T201
print(f"html2print: ChromeDriver available at path: {path_to_chrome}") # noqa: T201

service = Service(path_to_chrome)

Expand All @@ -223,7 +223,7 @@ def create_webdriver(chromedriver: Optional[str], path_to_cache_dir: str):
# Enable the capturing of everything in JS console.
webdriver_options.set_capability("goog:loggingPrefs", {"browser": "ALL"})

print("html2pdf: creating ChromeDriver.", flush=True) # noqa: T201
print("html2print: creating ChromeDriver.", flush=True) # noqa: T201

driver = webdriver.Chrome(
options=webdriver_options,
Expand Down Expand Up @@ -295,7 +295,7 @@ def main():
)

path_to_chrome = get_chrome_driver(path_to_cache_dir)
print(f"html2pdf: ChromeDriver available at path: {path_to_chrome}") # noqa: T201
print(f"html2print: ChromeDriver available at path: {path_to_chrome}") # noqa: T201
sys.exit(0)

elif args.command == "print":
Expand All @@ -310,13 +310,13 @@ def main():

@atexit.register
def exit_handler():
print("html2pdf: exit handler: quitting the ChromeDriver.") # noqa: T201
print("html2print: exit handler: quitting the ChromeDriver.") # noqa: T201
driver.quit()

assert len(paths) % 2 == 0, (
f"Expecting an even number of input/output path arguments: {paths}."
)
for current_pair_idx in range(0, 2, len(paths)):
for current_pair_idx in range(0, len(paths), 2):
path_to_input_html = paths[current_pair_idx]
path_to_output_pdf = paths[current_pair_idx + 1]

Expand All @@ -331,7 +331,7 @@ def exit_handler():
with open(path_to_output_pdf, "wb") as f:
f.write(pdf_bytes)
else:
print("html2pdf: unknown command.") # noqa: T201
print("html2print: unknown command.") # noqa: T201
sys.exit(1)


Expand Down
4 changes: 2 additions & 2 deletions tests/integration/03_cache_dir_argument/test.itest
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ RUN: %html2pdf print --cache-dir %S/Output/cache %S/index.html %S/Output/index.p
RUN: %check_exists --file "%S/Output/index.pdf"
RUN: python %S/test.py

CHECK-RUN1: html2pdf: ChromeDriver does not exist in the local cache:
CHECK-RUN1: html2print: ChromeDriver does not exist in the local cache:

RUN: %html2pdf print --cache-dir %S/Output/cache %S/index.html %S/Output/index.pdf | filecheck %s --dump-input=fail --check-prefix CHECK-RUN2
RUN: %check_exists --file "%S/Output/index.pdf"
RUN: python %S/test.py

CHECK-RUN2: html2pdf: ChromeDriver exists in the local cache:
CHECK-RUN2: html2print: ChromeDriver exists in the local cache:
15 changes: 15 additions & 0 deletions tests/integration/04_two_documents/index1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html lang="">

<head>
<meta charset="utf-8">
<title>Test page</title>
<script src="../../../submodules/html2pdf/dist/bundle.js"></script>
<link rel="stylesheet" href="../../../submodules/html2pdf/test/shared/css/main.css">
</head>

<body>
<p>Hello world!</p>
</body>

</html>
15 changes: 15 additions & 0 deletions tests/integration/04_two_documents/index2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html lang="">

<head>
<meta charset="utf-8">
<title>Test page</title>
<script src="../../../submodules/html2pdf/dist/bundle.js"></script>
<link rel="stylesheet" href="../../../submodules/html2pdf/test/shared/css/main.css">
</head>

<body>
<p>Hello world!</p>
</body>

</html>
6 changes: 6 additions & 0 deletions tests/integration/04_two_documents/test.itest
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RUN: %html2pdf print %S/index1.html %S/Output/index1.pdf %S/index2.html %S/Output/index2.pdf

RUN: %check_exists --file "%S/Output/index1.pdf"
RUN: %check_exists --file "%S/Output/index2.pdf"

RUN: python %S/test.py
9 changes: 9 additions & 0 deletions tests/integration/04_two_documents/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from pypdf import PdfReader

reader = PdfReader("Output/index1.pdf")
assert len(reader.pages) == 1
assert reader.pages[0].extract_text() == "Hello world!"

reader = PdfReader("Output/index2.pdf")
assert len(reader.pages) == 1
assert reader.pages[0].extract_text() == "Hello world!"