Embed the PDF in a webpage without using the built-in PDF viewer

前端 未结 5 461
孤城傲影
孤城傲影 2020-12-15 10:18

Currently I am using the standard way to embed an pdf to the browser, however, the built-in pdf viewer for my target browser is not working as expected. I would like to forc

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-15 10:49

    Check out PDFObject which is a Javascript library to embed PDFs in HTML files. It handles browser compatibility pretty well and will most likely work on IE8.

    In your HTML, you could set up a div to display the PDFs:

    Then, you can have Javascript code to embed a PDF in that div:

    var pdf = new PDFObject({
      url: "https://sample.pdf",
      id: "pdfRendered",
      pdfOpenParams: {
        view: "FitH"
      }
    }).embed("pdfRenderer");
    

    Cheers

提交回复
热议问题