为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用jsreport和jsreport Chrome Pdf呈现1k pdf文件?

如何使用jsreport和jsreport Chrome Pdf呈现1k pdf文件?

绝地无双 2021-04-03 16:15:21
我试图能够使用Express.js生成端点报告,并使用Express.js生成端点,我在JSON中传递数组,API遍历它并在forEach循环中使用,然后将每个对象用于抓取门户网站,获取响应,然后创建一个PDF文件...这种方法是伪工作,但是我很确定存在一些并发问题...因为,如果我在JSON数组中传递2个项目,那么API可以毫无问题地创建2个PDF文件,但是如果我传递300个API,随机创建50 ...或60或120。这是我的jsreport配置const jsReportConfig = {  extensions: {    "chrome-pdf": {      launchOptions: {        timeout: 10000,        args: ['--no-sandbox', '--disable-setuid-sandbox'],      },    },  },  tempDirectory: path.resolve(__dirname, './../../temporal/pdfs'),  templatingEngines: {    numberOfWorkers: 4,    timeout: 180000,    strategy: 'http-server',  },};我像这样设置jsreport实例jsreport.use(jsReportChrome());jsreport.use(jsReportHandlebars());jsreport.init()而且,这就是我呈现报告的方式,该checkInvoiceStatus函数用作HTTP调用,返回返回到Handlebars模板中的HTML响应。const renderReports = (reporter, invoices) => new Promise(async (resolve, reject) => {    try {      const templateContent = await readFile(        path.resolve(__dirname, './../templates/hello-world.hbs'),        'utf-8',      );      invoices.forEach(async (invoice) => {        try {          const response = await checkInvoiceStatus(invoice.re, invoice.rr, invoice.id)          const $ = await cheerio.load(response);          const reporterResponse = await reporter.render({            template: {              content: templateContent,              engine: 'handlebars',              recipe: 'chrome-pdf',              name: 'PDF Validation',              chrome: {                displayHeaderFooter: true,                footerTemplate: '<table width=\'100%\' style="font-size: 12px;"><tr><td width=\'33.33%\'>{#pageNum} de {#numPages}</td><td width=\'33.33%\' align=\'center\'></td><td width=\'33.33%\' align=\'right\'></td></tr></table>',              },            },            data: {              taxpayerId: 'CAC070508MY2',              captcha: $('#ctl00_MainContent_ImgCaptcha').attr('src'),              bodyContent: $('#ctl00_MainContent_PnlResultados').html(),            },          });我不知道为什么,但是此功能在500毫秒后终止,但是文件是在1分钟后创建的...
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 356 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信