How to embed a PDF viewer in a page?

HtmlPdf

Html Problem Overview


If I'm not mistaken, Google Docs offers the means to display a PDF that is stored on the same server as the web page via an <iframe>, but I need to know how I can do this in a cross-browser compliant way.

Html Solutions


Solution 1 - Html

You could consider using PDFObject by Philip Hutchison.

Alternatively, if you're looking for a non-Javascript solution, you could use markup like this:

<object data="myfile.pdf" type="application/pdf" width="100%" height="100%">
  <p>Alternative text - include a link <a href="myfile.pdf">to the PDF!</a></p>
</object>

Solution 2 - Html

PDF.js is an HTML5 technology experiment that explores building a faithful and efficient Portable Document Format (PDF) renderer without native code assistance. It is community-driven and supported by Mozilla Labs.

You can see the demo here.

Solution 3 - Html

This might work a little better this way

<embed src= "MyHome.pdf" width= "500" height= "375">

Solution 4 - Html

If I'm not mistaken, the OP was asking (although later accepted a .js solution) whether Google's embedded PDF display server will display a PDF on his own website.

So, one and a half years later: yes, it will.

See http://googlesystem.blogspot.ca/2009/09/embeddable-google-document-viewer.html. Also, see https://docs.google.com/viewer, and plug in the URL of the file you want to display.

Edit: Re-reading, OP was asking for solutions that don't use iFrames. I don't think that's possible with Google's viewer.

Solution 5 - Html

have a try with Flex Paper http://flexpaper.devaldi.com/

it works like scribd

Solution 6 - Html

Be sure to test any solution across different Reader preferences. A site visitor may have their browser set to open the PDF in Reader/Acrobat as opposed to the browser, e.g., by disabling the Acrobat plugin in Firefox..

I can't be sure of my results, because I have two different Acrobat plugins that Firefox recognizes due to my having different versions of Adobe Acrobat and Adobe Reader, but it does appear that you at least need to test what happens if a website visitor has their browser set to not open the PDF in the browser. It could be quite annoying when they look at what appears to be an otherwise usable web page and their browser is nagging them to open a PDF file that they think they didn't request. In some cases, the PDF file spontaneously opened in Adobe Reader, not the browser, and in other cases the browser threw up a dialog saying the file didn't exist.

I ran into such mismatches with iframe and object both, different issues for different code.

This is for simple HTML code. I haven't tried the suggested frameworks.

Solution 7 - Html

using bootstrap you can have a responsive and mobile first embeded file.

<div class="embed-responsive embed-responsive-16by9">
  <iframe class="embed-responsive-item" src="address of your file" allowfullscreen></iframe>
</div>

Aspect ratios can be customized with modifier classes.
<!-- 21:9 aspect ratio -->
<div class="embed-responsive embed-responsive-21by9">
  <iframe class="embed-responsive-item" src="..."></iframe>
</div>

<!-- 16:9 aspect ratio -->
<div class="embed-responsive embed-responsive-16by9">
  <iframe class="embed-responsive-item" src="..."></iframe>
</div>

<!-- 4:3 aspect ratio -->
<div class="embed-responsive embed-responsive-4by3">
  <iframe class="embed-responsive-item" src="..."></iframe>
</div>

<!-- 1:1 aspect ratio -->
<div class="embed-responsive embed-responsive-1by1">
  <iframe class="embed-responsive-item" src="..."></iframe>
</div>

Solution 8 - Html

pdf2htmlEX by coolwanglu is probably the best solution out there to convert a pdf file into html. You could do a simple convert and then embed the html page as an iframe or something similar.

Solution 9 - Html

I would really opt for FlowPaper, especially their new Elements mode that can be found here : https://flowpaper.com/demo/

It flattens the PDFs significantly at the same time as keeping text sharp which means that it will load much faster on mobile devices

Solution 10 - Html

<iframe src="https://docs.google.com/viewer?url=**https://www.fsc.esn.ac.lk/sites/default/files/2021-10/AcSchedule.pdf**&embedded=true" style="width:100%; height:500px;" frameborder="0"></iframe>

Should replace the URL https://www.fsc.esn.ac.lk/sites/default/files/2021-10/AcSchedule.pdf with your own address

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndrei OnigaView Question on Stackoverflow
Solution 1 - HtmlIan GregoryView Answer on Stackoverflow
Solution 2 - HtmlmutilView Answer on Stackoverflow
Solution 3 - HtmlDoesEatOatsView Answer on Stackoverflow
Solution 4 - HtmlJonView Answer on Stackoverflow
Solution 5 - HtmlNetoricaView Answer on Stackoverflow
Solution 6 - HtmlCharles BelovView Answer on Stackoverflow
Solution 7 - HtmlSina RiyaziView Answer on Stackoverflow
Solution 8 - HtmlDreizeilerView Answer on Stackoverflow
Solution 9 - HtmlRobbyView Answer on Stackoverflow
Solution 10 - HtmlKuhanView Answer on Stackoverflow