Reputation: 21
I need to generate a report with formulas. I found the library rst2pdf. I like to work with the library, but there was a problem when generating pdf with formulas. To generate a formula I use math role. The following code does not work. The error occurs in the module PIL. How to fix it.
#!/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')
Output of the script
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1549, in save
raise KeyError(ext) # unknown extension
KeyError: '.png'
Upvotes: 1
Views: 1167
Reputation: 1039
This error happens when PIL/Pillow does not recognise the file extension chosen to save with.
from PIL import Image
im = Image.new("RGB", (100, 100))
im.save("test", ".png")
gives
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "lib/python3.7/site-packages/PIL/Image.py", line 1939, in save
save_handler = SAVE[format.upper()]
KeyError: '.PNG'
This is because ".png" is not a valid format, "png" is. What you need to do is
im.save("test", "png")
or
im.save("test.png")
Upvotes: 0