Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed PDF file with responsive width

I'm embedding pdf files using something like this:

<div class="graph-outline">
    <object style="width:100%;" data="path/to/file.pdf?#zoom=85&scrollbar=0&toolbar=0&navpanes=0" type="application/pdf">
    <embed src="path/to/file.pdf?#zoom=85&scrollbar=0&toolbar=0&navpanes=0" type="application/pdf" />
    </object>
</div>

It works but I want to set the pdf width to match the width of the containing div. Currently it shows up like an iframe with scrollbars, so to view the entire pdf, you have to scroll right to left. I want the pdf to fit the width of the container.

How do I fix this? I'm supporting IE8 and up.

Here is a jsfiddle: http://jsfiddle.net/s_d_p/KTkcj/

like image 618
emersonthis Avatar asked May 09 '13 18:05

emersonthis


People also ask

Can you make a PDF responsive?

To make the content of PDF document responsive, we need to pull all the data out of the PDF file and write them to another format that supports responsive layout. Accessing and recognizing elements of the PDF file is not easy. But fortunately, our PDFix SDK Library can do that and the results are very precise!

How do you display a PDF using an iframe and make it responsive?

All you need to do is add #view=fitH to the end of the source attribute. That's it! fitH stands for fit horizontal, and this will make the PDF in our iframe fit the width of the screen.

How do I embed a PDF document?

To attach a file, go to Insert > Attach File in PDF. To embed a file, go to Insert > Embed File in PDF. Browse to and select the file that you want to insert, and click Select on the Select File dialog.

How do I embed a PDF in HTML?

Using an iframe tag is the second way to embed a pdf file in an HTML web page. In web development, web developers use the iframe tag to embed files in various formats and even other websites within a web page. Due to its wide compatibility, the iframe tag is widely used for embedding pdf.

How to embed PDF viewer in HTML?

How to embed PDF viewer in HTML ¶. Another way of adding a PDF file to your HTML document is using the <iframe> tag. It allows setting your preferred width and height as well. To have the code, follow these simple steps: To specify the web address of your PDF file, set the source. Both of the mentioned properties can be specified by "px", "cm", ...

How responsive are PDFs?

I think pdfs are as responsive as large amounts of tabular data - they arent. I dont think there is anything you can do because it is a fixed size - sure you can reduce the size in the browser window but its unreadable.

How to display a PDF file on a web page?

Generally, a hyperlink is used to link a PDF document to display in the browser. HTML anchor link is the easiest way to display a PDF file. But if you want to display PDF document on the web page, PDF file need to be embedded in HTML. The HTML < embed > tag is the best option to embed PDF document on...

How do I make the PDF in an iframe responsive?

The size of the iframe is responsive, but the PDF inside is not. I’ll keep this quick. All you need to do is add #view=fitH to the end of the source attribute. That’s it! fitH stands for fit horizontal, and this will make the PDF in our iframe fit the width of the screen.


5 Answers

Simply do this:

<object data="resume.pdf" type="application/pdf" width="100%" height="800px"> 
  <p>It appears you don't have a PDF plugin for this browser.
   No biggie... you can <a href="resume.pdf">click here to
  download the PDF file.</a></p>  
</object>
like image 198
dhanasekar Avatar answered Oct 21 '22 02:10

dhanasekar


If you're using Bootstrap 3, you can use the embed-responsive class and set the padding bottom as the height divided by the width plus a little extra for toolbars. For example, to display an 8.5 by 11 PDF, use 130% (11/8.5) plus a little extra (20%).

<div class='embed-responsive' style='padding-bottom:150%'>
    <object data='URL.pdf' type='application/pdf' width='100%' height='100%'></object>
</div>

Here's the Bootstrap CSS:

.embed-responsive {
    position: relative;
    display: block;
    height: 0;
    padding: 0;
    overflow: hidden;
}
like image 27
C. David Maxey Avatar answered Oct 21 '22 03:10

C. David Maxey


I did that mistake once - embedding PDF files in HTML pages. I will suggest that you use a JavaScript library for displaying the content of the PDF. Like https://github.com/mozilla/pdf.js/

like image 3
chrwahl Avatar answered Oct 21 '22 01:10

chrwahl


<embed src="your.pdf" type="application/pdf#view=FitH" width="actual-width.px" height="actual-height.px"></embed>

Check this link for all PDF Parameters: https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf#page=7

Chrome has its own PDF reader & all parameter don't work on chrome. Mozilla is worst for handling PDFs.

like image 3
dig99 Avatar answered Oct 21 '22 02:10

dig99


<html>
<head>
<style type="text/css">
#wrapper{ width:100%; float:left; height:auto; border:1px solid #5694cf;}
</style>
</head>
<div id="wrapper">
<object data="http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf" width="100%" height="100%">
<p>Your web browser doesn't have a PDF Plugin. Instead you can <a href="http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf"> Click
here to download the PDF</a></p>
</object>
</div>
</html>
like image 1
Surya R Praveen Avatar answered Oct 21 '22 03:10

Surya R Praveen