Skip to content

Commit

Permalink
add constants and fix pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
dayesouza committed Apr 12, 2024
1 parent 33e2276 commit 5b7998b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 6 additions & 0 deletions app/util/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2024 Microsoft Corporation. All rights reserved.

# PDF Generation
PDF_MARGIN_INCHES = 0.75
PDF_ENCODING = 'UTF-8'
PDF_WKHTMLTOPDF_PATH = 'C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'
17 changes: 10 additions & 7 deletions app/util/wkhtmltopdf.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) 2024 Microsoft Corporation. All rights reserved.
import os
import pdfkit
import util.constants as constants

# Specify the name of the executable
executable = 'wkhtmltopdf'

# Check if the executable is in the system PATH
def is_in_path(executable):
for path in os.environ["PATH"].split(os.pathsep):
Expand All @@ -12,16 +12,19 @@ def is_in_path(executable):
return False

def config_pdfkit():
path_wkhtmltopdf = 'C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'
path_wkhtmltopdf = constants.PDF_WKHTMLTOPDF_PATH

# Verify if wkhtmltopdf is in PATH
if is_in_path(executable):
if is_in_path('wkhtmltopdf'):
path_wkhtmltopdf=''
else:
path_wkhtmltopdf = 'C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'

return pdfkit.configuration(wkhtmltopdf=path_wkhtmltopdf)

pdfkit_options = {
'encoding': 'UTF-8',
'margin-top': f'{constants.PDF_MARGIN_INCHES}in',
'margin-right': f'{constants.PDF_MARGIN_INCHES}in',
'margin-bottom': f'{constants.PDF_MARGIN_INCHES}in',
'margin-left': f'{constants.PDF_MARGIN_INCHES}in',
'encoding': constants.PDF_ENCODING,
'enable-local-file-access': True,
}

0 comments on commit 5b7998b

Please sign in to comment.