How to open generated pdf using jspdf in new window

后端 未结 14 2497
遇见更好的自我
遇见更好的自我 2020-12-04 15:50

I am using jspdf to generate a pdf file. Every thing is working fine. But how to open generated pdf in new tab or new window.

I am using



        
14条回答
  •  心在旅途
    2020-12-04 16:20

    Javascript code

    // IE doesn't allow using a blob object directly as link href
    // instead it is necessary to use msSaveOrOpenBlob
    if (window.navigator && window.navigator.msSaveOrOpenBlob) {
      window.navigator.msSaveOrOpenBlob(doc.output("blob"), "Name.pdf");
    } else {
    
      // For other browsers:
      // Create a link pointing to the ObjectURL containing the blob.
      doc.autoPrint();
      window.open(
        URL.createObjectURL(doc.output("blob")),
        "_blank",
        "height=650,width=500,scrollbars=yes,location=yes"
      );
    
      // For Firefox it is necessary to delay revoking the ObjectURL
      setTimeout(() => {    
        window.URL.revokeObjectURL(doc.output("bloburl"));
      }, 100);
    }
    

提交回复
热议问题