Specify Chrome path for converter.convert

All of a sudden my converter.convert isn’t able to locate chrome.

from pyhtml2pdf import converter
path = "D:/uploads/test.html"
pdf_file_path = "D:/uploads/test.pdf"
converter.convert(f'file:///{path}', pdf_file_path)

Where do I specify the path in my Windows setting instead of the python code in Windows as this script is to be deployed on linux ?

(env) PS D:\test> python convert-html-pdf.py
Traceback (most recent call last):
  File "D:\test\convert-html-pdf.py", line 4, in <module>
    converter.convert(f'file:///{path}', pdf_file_path)
  File "D:\test\env\lib\site-packages\pyhtml2pdf\converter.py", line 38, in convert
    result = __get_pdf_from_html(
  File "D:\test\env\lib\site-packages\pyhtml2pdf\converter.py", line 77, in __get_pdf_from_html
    driver = webdriver.Chrome(service=service, options=webdriver_options)
  File "D:\test\env\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
    super().__init__(
  File "D:\test\env\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 55, in __init__
    self.service.start()
  File "D:\test\env\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
    self._start_process(self._path)
  File "D:\test\env\lib\site-packages\selenium\webdriver\common\service.py", line 208, in _start_process
    self.process = subprocess.Popen(
  File "C:\Users\john\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\john\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1440, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application

Hi,

Did you ever find a solution for this problem?

Thanks for your help.

pyhtml2pdf was last updated a year ago.
So I ended up replacing it with playwright - far far better and more support -

pip install playwright
playwright install

Thank you! I will look into it…

1 Like