PDFKit,nodeJS合并两个PDF文件 [英] PDFKit, nodeJS merging two PDF files

查看:1574
本文介绍了PDFKit,nodeJS合并两个PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都没有使用NodeJS的PDFKit的经验.具体来说,我正在尝试将2个PDF文档合并为1个,但是似乎似乎无法正确地合并两个PDF的内容,而在合并的其中一个文件中却设置了格式.

does anyone have experience with PDFKit with NodeJS. Specifically, I'm trying to merge 2 PDF documents into 1, but I can't seem seem to get the content of the two PDFs properly with formatting inside the merged one.

这就是我要做的:

var PDFDocument = require('pdfkit');
var fs = require('fs');

var doc = new PDFDocument();
var fileName = 'test.pdf';
doc.pipe(fs.createWriteStream(fileName));

var file1 = '1.pdf';
var file2 = '2.pdf';

var stream1 = fs.createReadStream(file1);
doc.text(stream1);

doc.addPage();
var stream2 = fs.createReadStream(file2);
doc.text(stream2);

doc.end();

输出为test.pdf,应包含一个pdf,其中包含2个pdf格式相同的内容,但我只得到test.pdf,包含2页,每页包含一行"[对象对象]".我似乎找不到如何在doc.text()函数中重定向流的内容.

The output, that being test.pdf, should consist of a single pdf containing the contents of the 2 pdfs with the same formatting, but I'm only getting test.pdf with 2 pages, each consisting of a single line of "[Object object]". I can't seem to find how to redirect the content of the stream inside the doc.text() function.

关于我做错什么的任何想法,应该如何解决?

Any idea on what I do wrong, how should I fix it?

推荐答案

无法将两个PDF文档与pdfkit合并!

您可以为此目的使用 pdftk服务器.该程序提供了一个命令行界面,可以使用以下命令合并两个pdf文件:

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

这篇关于PDFKit,nodeJS合并两个PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆