HummusJS支持使用其appendPDFPagesFromPDF方法合并PDF
使用流与缓冲区一起使用的示例:
const hummus = require('hummus');const memoryStreams = require('memory-streams');const combinePDFBuffers = (firstBuffer, secondBuffer) => { var outStream = new memoryStreams.WritableStream(); try { var firstPDFStream = new hummus.PDFRStreamForBuffer(firstBuffer); var secondPDFStream = new hummus.PDFRStreamForBuffer(secondBuffer); var pdfWriter = hummus.createWriterToModify(firstPDFStream, new hummus.PDFStreamForResponse(outStream)); pdfWriter.appendPDFPagesFromPDF(secondPDFStream); pdfWriter.end(); var newBuffer = outStream.toBuffer(); outStream.end(); return newBuffer; } catch(e){ outStream.end(); throw new Error('Error during PDF combination: ' + e.message); }};combinePDFBuffers(PDFBuffer1, PDFBuffer2);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)