我们打印模板需要使用lodop打印,目前的实现思路是使用ARJS生成pdf,将blob对象转成文件流传给后端,返回一个pdf链接,然后将pdf文件地址传给lodop打印,现在发现前端生成pdf这一步耗时太久,麻烦问下,这里有什么优化方案吗,或者有其他的解决方案吗
report
.load(reportResponse)
.then(function () {
return report.run()
})
.then(function (pageDocument) {
return PdfExport.exportDocument(pageDocument, settings)
})
.then(function (result) {
console.log(result)
var file = new File([result.data], 'a.pdf', {
type: 'application/json',
lastModified: Date.now(),
})
var form = new FormData()
// 文件
form.append('File', file)
// 调用封装好的上传方法,传给后台FormData
upload(form)
.then((res) => {
that.loading = false
if (res.Code == 10200) {
var strURLorContent = that.$filesUrl + res.Data.Path
let w, h
if (reportResponse.ReportSections) {
w = reportResponse.ReportSections[0].Page.PageWidth
h = reportResponse.ReportSections[0].Page.PageHeight
} else {
w = reportResponse.Page.PageWidth
h = reportResponse.Page.PageHeight
}
function repeatPrint(strURLorContent) {
LODOP.PRINT_INIT('测试PDF打印功能')
LODOP.SET_PRINT_PAGESIZE(0, w, h, 'CreateCustomPage')
LODOP.SET_PRINTER_INDEX(iPrinterIndex)
if (strURLorContent.indexOf('https') == -1) {
LODOP.ADD_PRINT_PDF(0, 0, '100%', '100%', strURLorContent) //http链接
} else {
LODOP.ADD_PRINT_PDF(
0,
0,
'100%',
'100%',
this.demoDownloadPDF(strURLorContent)
) //https链接
}
if (type == 'view') {
LODOP.PREVIEW()
} else {
LODOP.PRINT()
}
}
// 打印多次
for (let i = 0; i < that.count; i++) {
repeatPrint(strURLorContent)
}
} else {
that.$message.error(res.Msg)
}
})
.catch((response) => {
that.loading = false
that.$message.error('打印失败')
})
})
|