title: django PDF FileResponse "Failed to load PDF document."
body: <p>I am trying to generate and output PDF from a django view. I followed the example in <a href="https://docs.djangoproject.com/en/2.1/howto/outputting-pdf/" rel="nofollow noreferrer">django documentation using ReportLab</a> but the downloaded PDF is not opening in any PDF readers.</p>
  
  <p>I use Python 3.7.0, Django==2.1.3, reportlab==3.5.12. I tried adding <code>content_type="application/pdf"</code> to 'FileResponse` but still having the same issue.</p>
  
  <pre><code>import io
  from django.http import FileResponse
  from reportlab.pdfgen import canvas
  
  def printPDF(request):
      # Create a file-like buffer to receive PDF data.
      buffer = io.BytesIO()
  
      # Create the PDF object, using the buffer as its "file."
      p = canvas.Canvas(buffer)
  
  
      p.drawString(100, 100, "Hello world.")
  
  
      p.showPage()
      p.save()
  
      return FileResponse(buffer, as_attachment=True, filename='hello.pdf')
  </code></pre>
  
  <p>The generated PDF should be opening in all PDF readers. But I am getting 'Failed to load PDF document.'</p>