PDFKit, nodeJS merging two PDF files

巧了我就是萌 提交于 2019-12-06 00:31:40

It is not possible to merge two PDF documents with pdfkit!

You can use pdftk Server for that purpose. The program offers a command line interface, which could merge two pdfs with the following command:

pdftk 1.pdf 2.pdf cat output merged.pdf
var stream1 = fs.createReadStream(file1);

stream1.on('data', function(chunk) {
    console.log('got %d bytes of data', chunk.length);
    doc.contentStream(chunk);
});

stream1.on('end', function() {
    console.log('DONE with file1!!');
    doc.addPage();

    // now time to create and read from next stream.

});

You were creating the streams and writing the stream objects to the file. Instead you should write the data you read from the stream. But this won't be merging the files since you are reading the pdf markup and writing it as text to the next.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!