Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pdfkit/configuration.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
import os
import subprocess
import sys


class Configuration(object):
def __init__(self, wkhtmltopdf='', meta_tag_prefix='pdfkit-'):
def __init__(self, wkhtmltopdf='', meta_tag_prefix='pdfkit-', environ=''):
self.meta_tag_prefix = meta_tag_prefix

self.wkhtmltopdf = wkhtmltopdf
Expand All @@ -25,3 +26,12 @@ def __init__(self, wkhtmltopdf='', meta_tag_prefix='pdfkit-'):
'If this file exists please check that this process can '
'read it. Otherwise please install wkhtmltopdf - '
'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)

self.environ = environ

if not self.environ:
self.environ = os.environ

for key in self.environ.keys():
if not isinstance(self.environ[key], str):
self.environ[key] = str(self.environ[key])
6 changes: 4 additions & 2 deletions pdfkit/pdfkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def __init__(self, url_or_file, type_, options=None, toc=None, cover=None,
if self.source.isString():
self.options.update(self._find_options_in_meta(url_or_file))

self.environ = self.configuration.environ

if options is not None: self.options.update(options)

self.toc = {} if toc is None else toc
Expand Down Expand Up @@ -125,9 +127,9 @@ def command(self, path=None):

def to_pdf(self, path=None):
args = self.command(path)

result = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stderr=subprocess.PIPE, env=self.environ)

# If the source is a string then we will pipe it into wkhtmltopdf.
# If we want to add custom CSS to file then we read input file to
Expand Down