代码之家  ›  专栏  ›  技术社区  ›  San Jaisy

在Aungular 8中使用jsPDF的CSS PDF

  •  0
  • San Jaisy  · 技术社区  · 6 年前

    ERROR Error: You need either https://github.com/niklasvh/html2canvas or https://github.com/cburgmer/rasterizeHTML.js
        at Object.lt.API.addHTML (scripts.js:4138)
        at GenerateBackupCodesComponent.push../src/app/monash-identity/security/generate-backup-codes/generate-backup-codes.component.ts.GenerateBackupCodesComponent.backupCodesDownload (main.js:10699)
        at Object.eval [as handleEvent] (ng:///AppModule/GenerateBackupCodesComponent.ngfactory.js:105)
        at handleEvent (vendor.js:75740)
        at callWithDebugContext (vendor.js:76810)
        at Object.debugHandleEvent [as handleEvent] (vendor.js:76537)
        at dispatchEvent (vendor.js:66527)
        at vendor.js:74949
        at HTMLAnchorElement.<anonymous> (vendor.js:86116)
        at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (polyfills.js:3705)
    

    这是我的TS文件

    import * as jsPDF from 'jspdf';
    import * as html2canvas from 'html2canvas';
    
    
      public backupCodesDownload() {
        const doc = new jsPDF();
    
        const specialElementHandlers = {
          '#editor': function (element, renderer) {
            return true;
          }
        };
    
        const content = this.downloadPanelContent.nativeElement;
    
        doc.addHTML(content.innerHTML, 0, 0, {
          'width': 100, // max width of content on PDF
          'elementHandlers': specialElementHandlers
        },
          function save() { doc.save('BackupCodes.pdf'); window.open(doc.output('bloburl')); }, 0);
      }
    

    包.Json

     "dependencies": {
        "html2canvas": "^1.0.0-rc.5",
        "jspdf": "^1.5.3"
    }
    

    "scripts": [
                  "./node_modules/jspdf/dist/jspdf.min.js"
                ]
    

    我也将脚本直接添加到Index.html页面,但遇到了同样的问题。

    工具书类 https://github.com/MrRio/jsPDF/issues/270

    https://github.com/MrRio/jsPDF/issues/1693

    https://github.com/MrRio/jsPDF/issues/1225

    Angular2 - Generate pdf from HTML using jspdf

    0 回复  |  直到 6 年前