Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap modal - Add a object tag embedding a PDF

I'm currently trying to display a bootstrap modal in which I want to include a PDF file with the "object" html tag. Problem is that nothing seems to display.

I've created a jsFiddle (http://jsfiddle.net/mV6jJ/3/).

So you will find a basic modal (exactly same code from bootstrap for a basic modal showing after a click on a button) and in the modal-body you will find :

<object type="application/pdf" data="http://www.inkwelleditorial.com/pdfSample.pdf" width="500" height="500">this is not working as expected</object>

So when I add this code alone (so not inside a bootstrap modal) it's working as expected. It display the pdf in the browser's default pdf viewer. But when I try to implement the pdf inside of the bootstrap modal, nothing seems to appear.

If you have any idea it will really helps me, many hours searching and I've only seen solutions with tag (which I don't want to use).

Thank you and best regards

like image 358
Tidus Avatar asked Apr 28 '14 12:04

Tidus


People also ask

How do I embed a PDF in Bootstrap?

This is a simple example using <object> to embed a PDF file into an HTML page, but the PDF display window does not match the viewport of the browser. And here's the Bootstrap solution: Wrap <iframe>/<object>/.. by <div class="embed-responsive embed-responsive-*by*">. Of which: (*) is a number.

Can you put an IFrame in a modal?

IFrames are used to insert content from other source. With the Bootstrap integration, you can put the content of the IFrame inside a modal to make it even more interactive and entertaining.

How can I add modal image?

Images can be fitted in modal popup using Bootstrap by including <img> tag in the “modal-body” div. The “modal-body” div determines the main content of modal popup. By using the <img> tag, an image can be inserted into it.

How do I show a Bootstrap modal inside a div?

To show a bootstrap modal inside a div the logic behind the above code is to append the HTML code of the modal as well as the modal-backdrop inside that specific div(blue div whose position is relative) and then making the CSS for modal and modal-backdrop to position:absolute so that the modal and its background gets ...


2 Answers

I have found that bootstrap include a css property that affect to pdf viewing in a modal window.

Change this:

.modal.in .modal-dialog {
  transform: translate(0px, 0px);
}

to:

.modal.in .modal-dialog {
  transform: none;
}

If this property is changed everything works properly.

You can see in action:

http://jsfiddle.net/mV6jJ/20/

like image 148
kesser Avatar answered Sep 18 '22 18:09

kesser


Prevent download manager: Again, if you have Internet Download Manager or any other download manager that catches pdf automatically try to prevent it from auto catch pdf link.

Also checkout PDFObject JS, it should be interesting

<script src="https://github.com/pipwerks/PDFObject/blob/master/pdfobject.min.js"></script>

EDIT

Please try iframe instead object type pdf

<iframe src="http://www.inkwelleditorial.com/pdfSample.pdf" width="500" height="500"></iframe>

http://jsfiddle.net/mV6jJ/9/

like image 31
sir4ju1 Avatar answered Sep 20 '22 18:09

sir4ju1