from teleforma.context_processors import *
import jqchat.models
from xlwt import Workbook
-from xhtml2pdf import pisa
try:
from telecaster.models import *
from cgi import escape
from cStringIO import StringIO
-from xhtml2pdf import pisa
+import weasyprint
import time
import json
Write into *dest* file object the given html *content*.
Return True if the operation completed successfully.
"""
- from xhtml2pdf import pisa
+ print("Write PDF 2")
src = StringIO(content.encode(encoding))
- pdf = pisa.pisaDocument(src, dest, encoding=encoding, **kwargs)
- return not pdf.err
+ src = weasyprint.HTML(string=content.encode(encoding), encoding=encoding)
+ dest.write_pdf(result)
+ return True
def content_to_response(content, filename=None):
"""
template_name = 'myapp/myview.html'
pdf_filename = 'report.pdf'
- The pdf generation is automatically done by *xhtml2pdf* using
+ The pdf generation is automatically done by *weasyprint* using
the *myapp/myview_pdf.html* template.
Note that the pdf template takes the same context as the normal template.