Angular2 - Generate pdf from HTML using jspdf

后端 未结 5 1461
梦如初夏
梦如初夏 2020-12-20 13:09

For a project I\'m working on I need to be able to generate a PDF of the page the user is currently on, for which I\'ll use jspdf. Since I have a HTML

5条回答
  •  心在旅途
    2020-12-20 13:37

    Use this way stackblitz example

    import {jsPDF} from 'jspdf';
    
    @ViewChild('content', {static: false}) content: ElementRef;
    
    
    public downloadPDF() {
       const doc = new jsPDF();
    
       const specialElementHandlers = {
          '#editor': function (element, renderer) {
           return true;
           }
       };
    
       const content = this.content.nativeElement;
    
       doc.fromHTML(content.innerHTML, 15, 15, {
          width: 190,
         'elementHandlers': specialElementHandlers
       });
    
       doc.save('fileName.pdf');
    }
    

提交回复
热议问题