我需要用公式生成报告。我找到了图书馆 rst2pdf。我喜欢使用该库,但是在使用公式生成 pdf 时出现问题。要生成公式,我使用数学角色。以下代码不起作用。错误发生在模块 PIL 中。如何修复它。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from rst2pdf.createpdf import RstToPdf
mytext = u"""
================
Name of document
================
Title
---------
==================== ========== ==========
Header row, column 1 Header 2 Header 3
==================== ========== ==========
body row 1, column 1 column 2 column 3
body row 2, column 1 column 2 column 3
body row 3, column 1 column 2 column 3
==================== ========== ==========
:math:`\\frac{1}{\\sigma\\sqrt{2\\pi}}\\exp\\left(-\\frac{(x-\\mu)^2}{2\\sigma^2}\\right) = 123`
"""
pdf = RstToPdf()
pdf.createPdf(text = mytext, output='foo.pdf')
脚本的输出
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1549, in save
raise KeyError(ext) # unknown extension
KeyError: '.png'