如何使用网址中的pdfkit(node Js)将具有某些内容的两个图像粘贴到pdf?

问题描述 投票:-1回答:1

实际上,使用reques和pdfkit模块可以轻松地粘贴一张图像。但是我很困惑如何将2张图片从url添加到pdf?

var PDF = require('pdfkit');            
var fs = require('fs');                 
var text = "ANY_TEXT_YOU_WANT_TO_WRITE_IN_PDF_DOC";        
var request = require('request');
doc = new PDF();                        
doc.pipe(fs.createWriteStream('/home/oodles/testing_file.pdf'));  
            request({
                url: 'https://images.unsplash.co&auto=format&fit=crop&w=500&q=60',
                encoding: null 
              }, function(err, response, body) {
              if (err) throw err;
              doc.image(body,260, 50,{height:100,width:100});
              doc.text('HOLIDAYS - 125 Fortime',80,165,{align:'center'})
              doc.text('Hello this is a demo file',100,200)
              doc.end(); 
              return;
    });

我要从网址获得2张或更多图片怎么做 ??在此先感谢

javascript node.js pdfkit node-pdfkit
1个回答
0
投票

您可以尝试这个....

ImagesUrlArr.forEach(function (el){
    doc.addPage().image(el.data, {fit: [500, 400], align: 'center',valign: 'center'})
})
© www.soinside.com 2019 - 2024. All rights reserved.