Skip to content

Instantly share code, notes, and snippets.

@apexdodge
Created June 17, 2018 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apexdodge/0160c883650afe4f4c68f0223b3b6375 to your computer and use it in GitHub Desktop.
Save apexdodge/0160c883650afe4f4c68f0223b3b6375 to your computer and use it in GitHub Desktop.
"""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