1
我expressJs應用我要去保存圖像在PDF文件下面是我的代碼保存圖像在PDF文件不保存圖像中的節點/ expressJs PDF收到錯誤
exports.getPDF = function (req, res) {
doc = new PDF();
doc.pipe(fs.createWriteStream('./public/Competition.pdf'));
db.competitions.find({where: {id: req.params.competitionId}}).success(function(competition){
//MY_URL_IS = http://d16dgegkincj5i.cloudfront.net/1_2_brandLogo_new_update_code-thumbnail.png
var options = {
host: 'http://d16dgegkincj5i.cloudfront.net',
port: 80,
path: '/1_2_brandLogo_new_update_code-thumbnail.png'
}
var request = http.get(options, function(res){
var imagedata = ''
res.setEncoding('binary')
res.on('data', function(chunk){
imagedata += chunk
})
res.on('end', function(){
fs.writeFile('./public/Competition.pdf', imagedata, 'binary', function(err){
if (err) throw err
console.log('File saved.')
})
})
})
}).error(function(error){
});
};
我收到錯誤
events.js:85
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
當我通過http.get和寫入PDF文件後得到的圖像,它會給錯誤,不寫入圖像
謝謝,但一個問題是圖像保存爲未在PDF文件PDF是存在在我的代碼 –
好@Sarkar任何錯誤,我明白。我不知道(你沒有在你的問題中說過)你用來創建PDF文件的模塊。但事實是:現在這是另一個問題,因爲您提到的錯誤已由所提供的解決方案修復。請隨時提出另一個問題,詳細解釋目前的問題,我很樂意提供幫助。 –
我有一個node.js應用程序,我正在使用pdfkit生成pdf文檔。我希望能夠在pdf文件中包含來自url的圖像 –