所以我试图将网站的一部分导出为 PDF,并且我能够成功导出 HTML,但 CSS 代码只是作为实际文本输出。
def exportPDf(results, css, html):
result = StringIO.StringIO()
results_2 = StringIO.StringIO(results.encode("UTF-8"))
css_encode = StringIO.StringIO(css.encode("UTF-8"))
pdf = pisa.pisaDocument(results_2 , result)#ISO-8859-1
if not pdf.err:
return HttpResponse(result.getvalue(), mimetype='application/pdf')
return HttpResponse('We had some errors<pre>%s</pre>' % escape(html))
def get_data(request):
results = request.GET['css'] + request.GET['html']
html = request.GET['html']
css = request.GET['css']
return ExportPDf(results, css, html)