2016-07-16 64 views
1

我有问题当我在多个页面上传pdf文件,然后生成多个时间的拇指。如何生成拇指pdf文件只节点js的第一页

我的代码如下

var image = random() + '.png'; 
imagename = 'uploads/document_thumb/' + image; 
var pathToFile = path.join(__dirname, req.files[i].path) 
, pathToSnapshot = path.join(__dirname, '/uploads/document_thumb/' + image); 

    im.resize({ 
      srcPath: pathToFile 
     , dstPath: pathToSnapshot 
     , width: 150 
     , height: 150 
     , quality: 0 
     , gravity: "North" 
    }, 
    function (err, stdout, stderr) { 
    if (err) { 
        console.log(err); 
      } 
    console.log('resized image', pathToSnapshot); 
    }); 

如何设置生成只有一个页面拇指产生。

回答

0

我使用GraphicsMagick生成Pdf文件的大拇指。

var gm = require('gm'); 
    var image = random() + '.png'; 
     var pathToFile = path.join(__dirname, req.files[i].path) 
     , pathToSnapshot = path.join(__dirname, '/uploads/document_thumb/' + image); 
     gm(pathToFile).thumb(150, // Width 
          150, // Height 
          pathToSnapshot, // Output file name 
          40, // Quality from 0 to 100 
     function (error, stdout, stderr, command) { 
      if (!error) { 
         console.log(command); 
        } 
        else { 
         console.log(error); 
        } 
       });