0

Currently I am Working on a workflow where on the left side are input fields and on the right half is a scalable pdf.

But actually I am not able to show a PDF in an iframe.

I am using django 2.1.1(python 3.7.2) on windows. Is there any solution to display a pdf in an iframe?

I hope you have some ideas..i looked up many sides an tried different solution but actually the pdf document is not shown.. Hope to hear from you soon!

Kind regards

Bartnatz
  • 13
  • 6
  • 1
    Possible duplicate of https://stackoverflow.com/questions/19654577/html-embedded-pdf-iframe – tomgalpin Nov 20 '19 at 15:58
  • Does this answer your question? [HTML embedded PDF iframe](https://stackoverflow.com/questions/19654577/html-embedded-pdf-iframe) – Joel Anderson Nov 20 '19 at 17:02
  • Sorry, but this is not a duplicate of this. Actually the recommendation did not help. – Bartnatz Nov 21 '19 at 06:31
  • To be honest, it does not have to be an iframe, it could be everything. But at the moment I am not able to display a pdf document in the browser width django. Is there no solution for this problem? – Bartnatz Nov 21 '19 at 06:33
  • It does not work, I tested it with pdf.js and the document is not loading, I got no error in the console, the document is really not loading. So Is there any recommendation which is helpful? I can not believe that I am the only one which is struggling with a Pdf viewer in django. – Bartnatz Nov 25 '19 at 14:09

1 Answers1

1

I have experienced a similar setting where I wanted to render a PDF in a webpage. For that, I did the following : Wrote a view method (in views.py) that renders the pdf's name. Indicated in the urls.py the path used for the view method. Next, in the HTML file, I use the following line of code :

<iframe id="iframe_pdf" src="{{ doc_file.url }}" 
      style="width:800px; height:800px;" frameborder="0"></iframe>

The {{ doc_file.url }} is the data obtained from the View method, it returns the PDF file location as a string. In my case, the pdfs were stored in the MEDIA_ROOT directory set in settings.py.

Red
  • 26,798
  • 7
  • 36
  • 58
alpha027
  • 302
  • 2
  • 13