我有一个客户,希望我获取一个url或pdf文件,将其更改为图像,然后将其保存到目标文件夹。我有一些代码,但是我对去哪里有些困惑。
如果有人能指出正确的方向,我将不胜感激。
我会这样:
您应该定义您的输入内容。它可以是PDF文件或网站链接,对吧?
如果是网站,请使用:https://github.com/brenden/node-webshot
如果是PDF,请使用[https://github.com/mooz/node-pdf-image
然后,使用node.js内置文件系统功能移动文件:https://www.tutorialspoint.com/nodejs/nodejs_file_system.htm
起点看起来像这样:
const webshot = require('webshot');
const fs = require('fs');
const renderStream = webshot('google.com');
const file = fs.createWriteStream('google.png', {encoding: 'binary'});
renderStream.on('data', function(data) {
file.write(data.toString('binary'), 'binary');
});