Created
June 17, 2018 12:08
-
-
Save apexdodge/0160c883650afe4f4c68f0223b3b6375 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Module for manipulating and generating PDFs""" | |
import os | |
import subprocess | |
import platform | |
import pdfkit | |
def _get_pdfkit_config(): | |
"""wkhtmltopdf lives and functions differently depending on Windows or Linux. We | |
need to support both since we develop on windows but deploy on Heroku. | |
Returns: | |
A pdfkit configuration | |
""" | |
if platform.system() == 'Windows': | |
return pdfkit.configuration(wkhtmltopdf=os.environ.get('WKHTMLTOPDF_BINARY', 'C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe')) | |
else: | |
WKHTMLTOPDF_CMD = subprocess.Popen(['which', os.environ.get('WKHTMLTOPDF_BINARY', 'wkhtmltopdf')], stdout=subprocess.PIPE).communicate()[0].strip() | |
return pdfkit.configuration(wkhtmltopdf=WKHTMLTOPDF_CMD) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment