tutorcruncher / pydf

PDF generation in python using wkhtmltopdf for heroku and docker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

error in windows

jgmtzmd opened this issue · comments

hi.
i have a script working alright in linux (openuse).
tried to use it in a windows machine and doesnt.

even tried the simple example:
pdf = pydf.generate_pdf('<h1>this is html</h1>')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Miniconda3\lib\site-packages\pydf\wkhtmltopdf.py", line 145, in generate_pdf
    p = _execute_wk(*cmd_args, input=html.encode())
  File "C:\ProgramData\Miniconda3\lib\site-packages\pydf\wkhtmltopdf.py", line 30, in _execute_wk
return subprocess.run(wk_args, input=input, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "C:\ProgramData\Miniconda3\lib\subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
  File "C:\ProgramData\Miniconda3\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
  File "C:\ProgramData\Miniconda3\lib\subprocess.py", line 990, in _execute_child
startupinfo)
OSError: [winerror 193]: %1 not a valid win32 program

Note: i traslated last line "OsError..". my machine threw that in spanish.

any trick to avoid this Error?
thanks.

The problem is that this package comes bundled with a wkhtmltopdf binary which is compiled for linux. That binary will never work on windows.

However as you can see here you can set an environment variable to use an alternative wkhtmltopdf binary.

I would try setting the environment variable WKHTMLTOPDF_PATH to C://path/to/wkhtmltopdf-binary and see if that works.

I'm afraid since I don't Windows at all I can't really help more than that, but if you do get it working I'd be happy to accept a pull request to add docs for Windows.

Alternatively, perhaps you could use the dockerized version since I know there are numerous routes to running docker on windows?

no problem, pleased it worked.