import pdfkit import config import sys import os han_list = ["零" , "一" , "二" , "三" , "四" , "五" , "六" , "七" , "八" , "九"] unit_list = ["","","十" , "百" , "千","万","十万","百万","千万","亿"] def four_to_han(num_str): result = "" num_len = len(num_str) for i in range(num_len): num = int(num_str[i]) if i!=num_len-1: if num!=0: result=result+han_list[num]+unit_list[num_len-i] else: if result[-1]=='零': continue else: result=result+'零' else: if num!=0: result += han_list[num] return result def convert_to_pdf(sourceHtml,outpdffile): path=resource_path(os.path.join("wkhtmltopdf","bin/wkhtmltopdf.exe")) configuration = pdfkit.configuration(wkhtmltopdf=path) options = { "enable-local-file-access": None, } try: pdfkit.from_file(sourceHtml, outpdffile, configuration=configuration, options=options) except Exception as e: { # print(str(e)) } #生成资源文件目录访问路径 def resource_path(relative_path): if getattr(sys, 'frozen', False): #是否Bundle Resource base_path = sys._MEIPASS else: base_path = os.path.abspath(".") return os.path.join(base_path, relative_path)