1

I'm using this pydf to convert HTML to a PDF on our server. This is an example that comes right from their docs that illustrates the problem:

import pydf

pdf = pydf.generate_pdf('<h1>this is html</h1>')
with open('test_doc.pdf', 'wb') as f:
    f.write(pdf)

When I go to run this file, I get the same error everytime:

(pdf) <computer>:<folder> <user>$ python pdf.py 
Traceback (most recent call last):
  File "pdf.py", line 3, in <module>
    pdf = pydf.generate_pdf('<h1>this is html</h1>')
  File "/Users/nilesbrandon/Projects/pdf/pdf/lib/python2.7/site-packages/pydf/wkhtmltopdf.py", line 121, in generate_pdf
    return gen_pdf(html_file.name, cmd_args)
  File "/Users/nilesbrandon/Projects/pdf/pdf/lib/python2.7/site-packages/pydf/wkhtmltopdf.py", line 105, in gen_pdf
    _, stderr, returncode = execute_wk(*cmd_args)
  File "/Users/nilesbrandon/Projects/pdf/pdf/lib/python2.7/site-packages/pydf/wkhtmltopdf.py", line 22, in execute_wk
    p = subprocess.Popen(wk_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception

I'm running this in a virtualenv and my pip freeze is only the following:

python-pdf==0.30

Any idea what could be going wrong here?

0

1 Answer 1

2

As you are using macOS, you need to download a wkhtmltopdf binary by your own:

pydf comes bundled with a wkhtmltopdf binary which will only work on Linux amd64 architectures. If you're on another OS or architecture your milage may vary, it is likely that you'll need to supply your own wkhtmltopdf binary and point pydf towards it by setting the WKHTMLTOPDF_PATH variable.

Sign up to request clarification or add additional context in comments.

4 Comments

Could you explain some steps I need to take to download a wkhtmltopdf binary on my own? Not sure where to start with that.
first download wkhtmltopdf from its website or with homebrew-cask, then set a env variable WKHTMLTOPDF_PATH=/usr/local/bin/wkhtmltopdf.
still having the issue actually.
@qarthandso what is your new issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.