Skip to content

Conversation

@Martin-Rehr
Copy link
Contributor

@Martin-Rehr Martin-Rehr commented Mar 22, 2018

Passing custom environment variables such as DISPLAY to wkhtmltopdf is necessary when using pdfkit with xvfbwrapper running in a cgi / wsgi setup.

Code example for usage with Xvfb:

import pdfkit
from xvfbwrapper import Xvfb

input = "Test"
input.encode("utf8")
vdisplay = Xvfb()
vdisplay.start()
env = os.environ
env['DISPLAY'] = ":%s" % vdisplay.vdisplay_num
configuration = pdfkit.configuration(environ=env)
pdfkit.from_string(input, 'out.pdf', configuration=configuration)
vdisplay.stop()

@alanhamlett
Copy link
Collaborator

This new code path is untested, can you add a test to make sure env vars are used as expected before merging?

@Martin-Rehr
Copy link
Contributor Author

What kind of tests would you like other than the example I posted with the pull request?

@alanhamlett
Copy link
Collaborator

You could write a unit test that mocks out os.environ and subprocess.Popen then expects a certain value from os.environ to show up in the call to Popen.

@Martin-Rehr
Copy link
Contributor Author

Martin-Rehr commented Apr 18, 2018

Would it be sufficient to show the effect of setting the PATH environment variable for wkhtmltopdf through subprocess.Popen ?

@alanhamlett alanhamlett merged commit 2c613d6 into JazzCore:master Apr 27, 2018
@alanhamlett
Copy link
Collaborator

I'll write tests for this in another PR. Thanks for the contribution!

@Martin-Rehr
Copy link
Contributor Author

Martin-Rehr commented Apr 30, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants