参考错误:在nodejs中运行jsdpf-autotable示例时未定义URL

时间:2019-11-15 11:23:56

标签: jspdf jspdf-autotable

  1. 我已经下载了jspdf的zip版本,并将其解压缩到我正在工作的存储库中。
  2. 作为自动表的示例代码,我还使用了this
  3. 我已经使用以下命令安装了jspdf:npm i D:\ lipsa_projects \ reportEmailService \ jsPDF-master
  4. 遵循here中的建议后,我尝试运行以下代码:

global.window = {document: {createElementNS: () => {return {}} }};
global.navigator = {};
global.html2pdf = {};
global.btoa = () => {};

const fs = require('fs');
const jsPDF = require('D:\phoenix_robotix\reportEmailService\jsPDF-master\dist\jspdf.node.debug');
require('jspdf-autotable');
require('D:\phoenix_robotix\reportEmailService\jsPDF-master\dist\jspdf.node.min')

const doc = new jsPDF();
doc.autoTable({
head: [
['ID', 'Name', 'Email', 'Country', 'IP-address'],
],
body: [
['1', 'HelloäöüßÄÖÜ', 'dmoore0@furl.net', 'China', '211.56.242.221'],
['2', 'Janice', 'jhenry1@theatlantic.com', 'Ukraine', '38.36.7.199'],
['3', 'Ruth', 'rwells2@constantcontact.com', 'Trinidad and Tobago', '19.162.133.184'],
['4', 'Jason', 'jray3@psu.edu', 'Brazil', '10.68.11.42'],
['5', 'Jane', 'jstephens4@go.com', 'United States', '47.32.129.71'],
['6', 'Adam', 'anichols5@com.com', 'Canada', '18.186.38.37']
],
});

const data = doc.output();

fs.writeFileSync('./document.pdf', data, 'binary');

delete global.window;
delete global.navigator;
delete global.btoa;
delete global.html2pdf;

我遇到以下错误:

function(t){var P,k,i,a,s,l,h,u,I,w,f,c,p,n,C,B,d,g,m,j;P=function(){return function(t){return e.prototype=t,new e};function e(){}}(),w=function(t){var e,n,r,i,o,a,s;for(n=0,r=t.length,e=void 0,a=i=!1;!i&&n!==r;)(e=t[n]=t[n].trimLeft())&&(i=!0),n++;for(n=r-1;r&&!a&&-1!==n;)(e=t[n]=t[n].trimRight())&&(a=!0),n--;for(o=/\s+$/g,s=!0,n=0;n!==r;)"\u2028"!=t[n]&&(e=t[n].replace(/\s+/g," "),s&&(e=e.trimLeft()),e&&(s=o.test(e)),t[n]=e),n++;return t},c=function(t){var e,n,r;for(e=void 0,n=(r=t.split(",")).shift();!e&&n;)e=i[n.trim().toLowerCase()],n=r.shift();return e},p=function(t){var e;return-1<(t="auto"===t?"0px":t).indexOf("em")&&!isNaN(Number(t.replace("em","")))&&(t=18.719*Number(t.replace("em",""))+"px"),-1<t.indexOf("pt")&&!isNaN(Number(t.replace("pt","")))&&(t=1.333*Number(t.replace("pt",""))+"px"),void 0,16,(e=n[t])?e:void 0!==(e={"xx-small":9,"x-small":11,small:13,medium:16,large:19,"x-large":23,"xx-large":28,auto:0}[t])?n[t]=e

ReferenceError: URL is not defined
    at D:\phoenix_robotix\reportEmailService\node_modules\jspdf\dist\jspdf.min.js:202:16491
    at D:\phoenix_robotix\reportEmailService\node_modules\jspdf\dist\jspdf.min.js:202:22171
    at D:\phoenix_robotix\reportEmailService\node_modules\jspdf\dist\jspdf.min.js:1:124
    at Object.<anonymous> (D:\phoenix_robotix\reportEmailService\node_modules\jspdf\dist\jspdf.min.js:1:128)
    at Module._compile (module.js:662:30)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)
    at Function.Module._load (module.js:507:3)
    at Module.require (module.js:606:17)

请帮助我调试代码并运行它。

0 个答案:

没有答案