我正在尝试使用NodeJS下载PDF文件,然后将其数据发送到客户端以嵌入页面中.以下是我下载PDF文件的方法:
exports.sendPdf = function(req, responce) {
var donneRecu = req.body;
var url = 'http://www.ieee.org/documents/ieeecopyrightform.pdf'//pdf link
http.get(url, function(res) {
var data = '';
res.on('data', function(chunk) {
console.log('downloading');
data += chunk;
});
res.on("end", function() {
console.log('downloaded');
responce.header("Access-Control-Allow-Origin", "*");
responce.header("Access-Control-Allow-Headers", "X-Requested-With");
responce.header(200, {'content-type' : 'application/pdf'});
responce.send(data);
});
}).on("error", function() {
callback(null);
});
}
Run Code Online (Sandbox Code Playgroud)
如何将从NodeJS收到的数据发送到客户端?
编辑 我找到了解决方案:
Run Code Online (Sandbox Code Playgroud)exports.sendPdf = function(req, res) { var donneRecu = req.body; console.log(donneRecu['lien']); var url = donneRecu['lien']; //pdf link http.get(url, function(response) { var chunks = []; response.on('data', function(chunk) { console.log('downloading'); …
我想知道是否有办法选择pdf文件input type="file"并使用PDFJS打开它
我可以将这样的数据传递给PDFJS.getDocument而不是URL.我的数据:
PDF-1.4% 9 0 obj <> endobj xref 9 36 0000000016 00000 n 0000001259 00000 n 0000001336 00000 n ...
我想知道是否有针对nodejs的Scrapy之类的东西?如果不是你怎么看待使用简单的页面下载并使用cheerio解析它?有没有更好的办法.