PPT/服务器启动/pdfkit_patch.py

41 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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报告")