How to open generated pdf using jspdf in new window

后端 未结 14 2375
遇见更好的自我
遇见更好的自我 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:06

    This works for me!!!

    When you specify window features, it will open in a new window

    Just like :

    window.open(url,"_blank","top=100,left=200,width=1000,height=500");
    
    0 讨论(0)
  • 2020-12-04 16:08

    This is how I handle it.

    window.open(doc.output('bloburl'), '_blank');
    
    0 讨论(0)
  • 2020-12-04 16:13

    Generally you can download it, show, or get a blob string:

    const pdfActions = {
        save: () => doc.save(filename),
        getBlob: () => {
          const blob = doc.output('datauristring');
          console.log(blob)
          return blob
        },
        show: () => doc.output('dataurlnewwindow')
      }
    
    0 讨论(0)
  • 2020-12-04 16:15

    I have to use this to load the PDF directly. Using doc.output('dataurlnewwindow'); produces an ugly iframe for me. Mac/Chrome.

      var string = doc.output('datauristring');
      var x = window.open();
      x.document.open();
      x.document.location=string;
    
    0 讨论(0)
  • 2020-12-04 16:19

    this code will help you to open generated pdf in new tab with required title

     let pdf = new jsPDF();
     pdf.setProperties({
              title: "Report"
          });
          pdf.output('dataurlnewwindow');
    
    0 讨论(0)
  • 2020-12-04 16:19

    using javascript you can send the generated pdf to a new window using the following code.

    var string = doc.output('datauristring');
    
    var iframe = "<iframe width='100%' height='100%' src='" + string + "'></iframe>"
    
    var x = window.open();
    x.document.open();
    x.document.write(iframe);
    x.document.close();
    
    0 讨论(0)
提交回复
热议问题