2

So I'm trying to export a section of a website to PDF, and Im able to export the HTML successfully, but the CSS codes just outputs as actual text.

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)
karthikr
  • 97,368
  • 26
  • 197
  • 188
bob
  • 41
  • 2
  • Have you taken a look at http://stackoverflow.com/questions/8986831/css-not-rendered-by-pisas-pdf-generation-in-django – JcKelley Jun 26 '13 at 02:55
  • Yes I've read a bunch of related questions,including that one, but they don't work. – bob Jun 26 '13 at 05:43

1 Answers1

0

You're not using css_encode anywhere. Try including that in your pisa call with results_2 and result.

computmaxer
  • 1,677
  • 17
  • 28
  • results_2 encodes results, which contains both CSS and HTML (from get_data). So if I include css_encode in PISA, it's including the CSS twice...I think. Should I NOT be combining CSS and HTML into one variable? And I did try to include it anyways like you suggested and got a "CStringIO.StringIO object has no attribute 'find'" error. – bob Jun 27 '13 at 00:47