Recommended way to embed PDF in HTML?

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

    Before I got a problem with embeding base64 encoded with PDF because the URI limitation, so any files over 2MB won't render properly on Chrome.

    My solution is:

    1. Convert uri encoded to Blob:

    2. Generate the temporary DOM String base on Blob.

      const blob = dataURItoBlob(this.dataUrl);

      var temp_url = window.URL.createObjectURL(blob);

    3. Decide where you want to attach the iframe to DOM:

      const target = document.querySelector(targetID);

      target.innerHTML = `

提交回复
热议问题