我需要将多个图像转换为一个 PDF。我可以为一张图片创建 PDF。当我有多个图像时,问题就来了。我如何创建多页 PDF。
最佳答案
我通过下面的代码得到了我想要的输出。
PDFDocument = require('pdfkit');
fs = require('fs');
doc = new PDFDocument
//Pipe its output somewhere, like to a file or HTTP response
//See below for browser usage
doc.pipe(fs.createWriteStream('output.pdf'))
//Add an image, constrain it to a given size, and center it vertically and horizontally
doc.image('./test.jpg', {
fit: [500, 400],
align: 'center',
valign: 'center'
});
doc.addPage()
.image('./1.png', {
fit: [500,400],
align: 'center',
valign: 'center'
});
doc.end()
关于node.js - 如何使用nodejs将多个图像转换为单个pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51054745/