Recommended way to embed PDF in HTML?

前端 未结 24 1692
天命终不由人
天命终不由人 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:27

    I found that the best way to embed a pdf for my case was by using bootstrap because not only does it show the pdf but it also fill available space and you can specify the ratio as you wish. Here's an example of what i made with it:

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
    
    <div class="embed-responsive embed-responsive-1by1">
      <iframe class="embed-responsive-item" src="http://example.com/the.pdf" type="application/pdf" allowfullscreen></iframe>
    </div>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

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

    I found this works just fine and the browser handles it in firefox. I have not checked IE...

    <script>window.location='url'</script>
    
    0 讨论(0)
  • 2020-11-21 05:29

    PdfToImageServlet using ImageMagick's convert command.

    Usage example: <img src='/webAppDirectory/PdfToImageServlet?pdfFile=/usr/share/cups/data/default-testpage.pdf'>

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

    I had to preview a PDF with React so after trying several libraries my optimal solution was to fetch the data and ebmed it.

    const pdfBase64 = //fetched from url or generated with jspdf or other library
    
      <embed
        src={pdfBase64}
        width="500"
        height="375"
        type="application/pdf"
      ></embed>
    
    0 讨论(0)
  • 2020-11-21 05:30

    If you don't want to host PDF.JS on your own, you could try DocDroid. It is similar to the Google Drive PDF viewer but allows custom branding.

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

    This is quick, easy, to the point and doesn't require any third-party script:

    <embed src="http://example.com/the.pdf" width="500" height="375" 
     type="application/pdf">
    

    UPDATE (1/2018):

    The Chrome browser on Android no longer supports PDF embeds. You can get around this by using the Google Drive PDF viewer

    <embed src="https://drive.google.com/viewerng/
    viewer?embedded=true&url=http://example.com/the.pdf" width="500" height="375">
    
    0 讨论(0)
提交回复
热议问题