合并节点中的PDF [英] Merging PDFs in Node

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

问题描述

您好我正在尝试合并总计 n 的pdf,但我无法让它发挥作用。



我正在使用缓冲模块用于连接pdf,但它只将最后一个pdf应用到最终的pdf中。



这在节点中是否可以做?

  var pdf1 = fs.readFileSync('。/ test1.pdf'); 
var pdf2 = fs.readFileSync('。/ test2.pdf');

fs.writeFile(./ final_pdf.pdf,Buffer.concat([pdf1,pdf2]),function(err){
if(err){
return console.log(错误);
}

console.log(文件已保存!);
});

目前有一些库,但它们都依赖于其他软件或编程语言。<你需要做什么 Buffer.concat([pdf1,pdf2])?只需连接两个PDF文件,就不会得到包含所有页面的文件。 PDF是一种复杂的格式(基本上是一种用于矢量图形)。如果您刚刚添加了两个JPEG文件,那么您不希望获得包含两张图片的大图像,是吗?



您需要使用外部库。 https://github.com/wubzz/pdf-merge 可能会起作用。


Hi i'm trying to merge pdf's of total of n but I cannot get it to work.

I'm using the Buffer module to concat the pdf's but it does only apply the last pdf in to the final pdf.

Is this even possible thing to do in node?

var pdf1 = fs.readFileSync('./test1.pdf');
var pdf2 = fs.readFileSync('./test2.pdf');

fs.writeFile("./final_pdf.pdf", Buffer.concat([pdf1, pdf2]), function(err) {
    if(err) {
        return console.log(err);
    }

    console.log("The file was saved!");
});

There are currently some libs out there but they do all depend on either other software or programming languages.

解决方案

What do you expect to get when you do Buffer.concat([pdf1, pdf2])? Just by concatenating two PDFs files you won’t get one containing all pages. PDF is a complex format (basically one for vector graphics). If you just added two JPEG files you wouldn’t expect to get a big image containing both pictures, would you?

You’ll need to use an external library. https://github.com/wubzz/pdf-merge might work for instance.

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

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