[Vuejs]-How to generate pdf in vuejs (UPDATED)

0👍

Maybe this piece of code will help you:
This will download pdf that you get from response

 const data = Buffer.from(bytes, 'binary');
 const blob = new Blob([data], { type: 'pdf' });
 if (window.navigator && window.navigator.msSaveOrOpenBlob) {
     window.navigator.msSaveBlob(blob, 'test.pdf');
    } else {
      const a = document.createElement('a');
      a.style = 'display: none';
      document.body.appendChild(a);
      const url = window.URL.createObjectURL(blob);
      a.href = url;
      a.download = fileName;
      a.click();

      window.URL.revokeObjectURL(url);
}

0👍

        exportpdf(){
            var self = this;
            var report= '';
            axios.get("http://34.67.88.0:8081/api/env/fdsfsdf")
            .then(function(res){
              let columns = [
                  {title:"Time",dataKey:"time"},
                  {title:"Temperature",dataKey:"Temperature"},
                  {title:"Humidity",dataKey:"Humidity"}
                  ];
              var doc = new jsPDF('p','pt');
              doc.autoTable(columns,res.data);
              doc.save("p.pdf");
             }) 
             }

Leave a comment