异常处理:在调用slide.get_image(1, 1)时,如果仍然出现RuntimeError: Proxy error(ArgumentException): Font '?' cannot be found.的错误,您可以考虑使用try-catch语句来捕获异常,并打印出更详细的错误信息,以便进行调试。
以下是您代码的一个改进版本,添加了异常处理:
import os
import aspose.slides as slides
# 输入PPT文件路径
input_path = "/home/code/test.pptx"
output_dir = "/home/code/output_images"
font_folder = "/home/code/Fonts/"
os.makedirs(output_dir, exist_ok=True)
# 加载PPT文件
presentation = slides.Presentation(input_path)
slides.FontsLoader.load_external_fonts([font_folder])
for i, slide in enumerate(presentation.slides):
output_path = os.path.join(output_dir, f"slide_{i+1}.jpeg")
try:
slide_image = slide.get_image(1, 1)
slide_image.save(output_path, slides.ImageFormat.JPEG)
print(f"PPT {i+1} 已保存为图像:{output_path}")
except Exception as e:
print(f"转换第 {i+1} 页时出错: {str(e)}")
slides.FontsLoader.clear_cache()
转换第 1 页时出错: Proxy error(ArgumentException): Font ‘?’ cannot be found.
转换第 2 页时出错: Proxy error(ArgumentException): Font ‘?’ cannot be found.
转换第 3 页时出错: Proxy error(ArgumentException): Font ‘?’ cannot be found.
转换第 4 页时出错: Proxy error(ArgumentException): Font ‘?’ cannot be found.
转换第 5 页时出错: Proxy error(ArgumentException): Font ‘?’ cannot be found.
转换第 1 页时出错: Proxy error(ArgumentException): Font ‘?’ cannot be found.
转换第 2 页时出错: Proxy error(ArgumentException): Font ‘?’ cannot be found.
转换第 3 页时出错: Proxy error(ArgumentException): Font ‘?’ cannot be found.
转换第 4 页时出错: Proxy error(ArgumentException): Font ‘?’ cannot be found.
转换第 5 页时出错: Proxy error(ArgumentException): Font ‘?’ cannot be found.
您能确认这一点吗? 您能否也将问题隔离,并提供精确的逐步说明以复现该问题?
您可以将包含文件的归档上传到文件存储服务(例如 Google Drive 或 Dropbox),然后分享链接。