import platform import os from module import create_filename import subprocess import appdirs from logger import logger def get_path_wkhtmltopdf() -> str: match platform.system(): case 'Linux': result = subprocess.Popen(['whereis wkhtmltopdf'], shell=True, stdout=subprocess.PIPE).stdout.read() path_programm = str(result).split(' ')[1] case 'Windows': path_programm = os.path.join("C:\\", "Program Files", "wkhtmltopdf", "bin", "wkhtmltopdf.exe") case _: return None if os.path.isfile(path_programm) and "wkhtmltopdf" in path_programm: logger.info(F"Find programm: {path_programm}") return path_programm else: return None def create_pdf(html_text) -> str: path_to = create_filename('pdf') path_temp_html = os.path.join(appdirs.user_cache_dir(), 'simple.html') with open(path_temp_html, 'w', encoding='utf-8') as file: file.write(html_text) logger.info(F"{get_path_wkhtmltopdf()} --enable-local-file-access {path_temp_html} {path_to}") subprocess.Popen([get_path_wkhtmltopdf(), "--enable-local-file-access", path_temp_html, path_to]) return path_to def main(): create_pdf('

Hello

') if __name__ == "__main__": main()