写了一个转pdf的函数,但是导出的pdf打开的时候提示文件损坏,应该是写入的内容有问题,但实在是不知道该如何解决先贴代码用到了两个库,pdfkit,和blob-streamlet doc = new PDFDocument() let stream = doc.pipe(blobStream()) // doc.pipe(fs.createWriteStream('Aim.pdf')) console.dir(stream) doc.fontSize(25).text('Here is some vector graphics...', 100, 80) // some vector graphics doc .save() .moveTo(100, 150) .lineTo(100, 250) .lineTo(200, 250) .fill('#FF3300') doc.circle(280, 200, 50).fill('#6600FF') // an SVG path doc .scale(0.6) .translate(470, 130) .path('M 250,75 L 323,301 131,161 369,161 177,301 z') .fill('red', 'even-odd') .restore() // end and display the document in the iframe to the right doc.end() // html5Bolb转arraybuffer // stream.toBlob('application/pdf') // console.log('转blob', stream._blob.length) // let reader = new FileReader() // reader.readAsArrayBuffer(stream._blob) // reader.onload = function (e) { // console.log('onloaded', reader.result) // } stream.on('finish', function() { stream.toBlob('application/pdf') // stream.toBlobURL('application/pdf') console.log('after', stream, doc) doc.pipe(fs.createWriteStream('Aim.pdf')) // // console.log('over', stream.toBlobURL('application/pdf')) console.log('over') })打印的内容如下不知该从哪儿下手了
添加回答
举报
0/150
提交
取消