Embedding pdfs in Django

570 views
Skip to first unread message

Vikas Sri

unread,
Nov 11, 2018, 1:09:48 PM11/11/18
to Django users
I am preparing learning tutorial application in Django, which will contain PDF's  that I need to display in my templates. I tried <embed>, <iframe> etc but nothing worked. Do I need to install something to make it work?

C. Kirby

unread,
Nov 13, 2018, 10:02:59 AM11/13/18
to Django users
I'm pretty sure that you can't render pdf to the browser. You can either provide links for the users to download and view the pdfs, or extract the content from the pdfs and put that in your templates.

You may be able to get what you want with javascript. I can't vouch for this, but I found it searching - https://pspdfkit.com/blog/2018/render-pdfs-in-the-browser-with-pdf-js/

good luck

Siim Märtmaa

unread,
Nov 13, 2018, 10:33:27 AM11/13/18
to django...@googlegroups.com
> On Sunday, November 11, 2018 at 1:09:48 PM UTC-5, Vikas Sri wrote:
>>
>> I am preparing learning tutorial application in Django, which will contain PDF's that I need to display in my templates. I tried <embed>, <iframe> etc but nothing worked. Do I need to install something to make it work?

Here is example and demo with pdf and <object> tag
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object

It should also work with iframe
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe

gibson...@u4sd.org

unread,
Nov 13, 2018, 1:01:49 PM11/13/18
to Django users
that is nice

gibson...@u4sd.org

unread,
Nov 13, 2018, 1:02:01 PM11/13/18
to Django users
great 


On Sunday, November 11, 2018 at 12:09:48 PM UTC-6, Vikas Sri wrote:
Reply all
Reply to author
Forward
0 new messages