41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import sys
|
||
import logging
|
||
|
||
# 配置日志
|
||
logging.basicConfig(level=logging.INFO)
|
||
logger = logging.getLogger("pdfkit_patch")
|
||
|
||
class PDFKitPatch:
|
||
"""pdfkit的兼容性替代类"""
|
||
|
||
@staticmethod
|
||
def from_string(html_content, output_path, options=None):
|
||
"""
|
||
将HTML字符串转换为PDF文件的兼容方法
|
||
仅记录操作,不实际生成PDF
|
||
"""
|
||
logger.info(f"[PDFKit兼容层] 请求将HTML转换为PDF:{output_path}")
|
||
|
||
# 保存原始HTML以供备用
|
||
html_output = output_path.replace('.pdf', '.html')
|
||
with open(html_output, 'w', encoding='utf-8') as f:
|
||
f.write(html_content)
|
||
|
||
logger.info(f"[PDFKit兼容层] 已保存HTML文件作为替代: {html_output}")
|
||
return True
|
||
|
||
@staticmethod
|
||
def from_file(input_file, output_file, options=None):
|
||
"""
|
||
将HTML文件转换为PDF的兼容方法
|
||
仅记录操作,不实际生成PDF
|
||
"""
|
||
logger.info(f"[PDFKit兼容层] 请求将文件转换为PDF: {input_file} -> {output_file}")
|
||
return True
|
||
|
||
# 导出兼容方法
|
||
from_string = PDFKitPatch.from_string
|
||
from_file = PDFKitPatch.from_file
|
||
|
||
# 向调用者提供信息
|
||
logger.info("pdfkit兼容层已加载,PDF生成功能已禁用,仅生成HTML报告") |