Recommended way to embed PDF in HTML?

前端 未结 24 1693
天命终不由人
天命终不由人 2020-11-21 04:54

What is the recommended way to embed PDF in HTML?

  • iFrame?
  • Object?
  • Embed?

What does Adobe say itself about it?

In my

相关标签:
24条回答
  • 2020-11-21 05:32
    1. Create a container to hold your PDF

      <div id="example1"></div>
      
    2. Tell PDFObject which PDF to embed, and where to embed it

      <script src="/js/pdfobject.js"></script>
      <script>PDFObject.embed("/pdf/sample-3pp.pdf", "#example1");</script>
      
    3. You can optionally use CSS to specify visual styling, including dimensions, border, margins, etc.

      <style>
      .pdfobject-container { height: 500px;}
      .pdfobject { border: 1px solid #666; }
      </style>
      

    source : https://pdfobject.com/

    0 讨论(0)
  • 2020-11-21 05:33

    just use iFrame for PDF's.

    I had specific needs in my React.js app, tried millions of solutions but ended up with an iFrame :) Good luck!

    0 讨论(0)
  • 2020-11-21 05:35
    1. Construct a blob of the input PDF bytes
    2. Use an iframe and PDF.js patched with this cross browser workaround

    The URI for the iframe should look something like this:

    /viewer.html?file=blob:19B579EA-5217-41C6-96E4-5D8DF5A5C70B
    

    Now FF, Chrome, IE 11, and Edge all display the PDF in a viewer in the iframe passed via standard blob URI in the URL.

    0 讨论(0)
  • 2020-11-21 05:37

    Using both <object> and <embed> will give you a wider breadth of browser compatibility.

    <object data="http://yoursite.com/the.pdf" type="application/pdf" width="750px" height="750px">
        <embed src="http://yoursite.com/the.pdf" type="application/pdf">
            <p>This browser does not support PDFs. Please download the PDF to view it: <a href="http://yoursite.com/the.pdf">Download PDF</a>.</p>
        </embed>
    </object>
    
    0 讨论(0)
  • 2020-11-21 05:38
    <object width="400" height="400" data="helloworld.pdf"></object>
    
    0 讨论(0)
  • 2020-11-21 05:39

    Probably the best approach is to use the PDF.JS library. It's a pure HTML5/JavaScript renderer for PDF documents without any third-party plugins.

    Online demo: http://mozilla.github.com/pdf.js/web/viewer.html

    GitHub: https://github.com/mozilla/pdf.js

    0 讨论(0)
提交回复
热议问题