Coverage for intelligence_toolkit/helpers/wkhtmltopdf.py: 100%
14 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-16 13:41 -0300
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-16 13:41 -0300
1# Copyright (c) 2024 Microsoft Corporation. All rights reserved.
2# Licensed under the MIT license. See LICENSE file in the project.
3#
4import os
6import pdfkit
8from . import constants
11# Specify the name of the executable
12# Check if the executable is in the system PATH
13def is_in_path(executable):
14 for path in os.environ["PATH"].split(os.pathsep):
15 if os.path.exists(os.path.join(path.strip('"'), executable)):
16 return True
17 return False
20def config_pdfkit():
21 path_wkhtmltopdf = constants.PDF_WKHTMLTOPDF_PATH
23 # Verify if wkhtmltopdf is in PATH
24 if is_in_path("wkhtmltopdf"):
25 path_wkhtmltopdf = ""
27 return pdfkit.configuration(wkhtmltopdf=path_wkhtmltopdf)
30pdfkit_options = {
31 "margin-top": f"{constants.PDF_MARGIN_INCHES}in",
32 "margin-right": f"{constants.PDF_MARGIN_INCHES}in",
33 "margin-bottom": f"{constants.PDF_MARGIN_INCHES}in",
34 "margin-left": f"{constants.PDF_MARGIN_INCHES}in",
35 "encoding": constants.PDF_ENCODING,
36 "enable-local-file-access": True,
37}