Tusharsangani Tusharsangani - 4 months ago 57
Javascript Question

How to generate thumb pdf file only first page in node js

I have issue When I upload pdf file in multiple page then generate thumb multiple time.

my code is below

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);
});


How to set generate only one page thumb generate.

Answer

I Use GraphicsMagick for generate thumb of Pdf File.

  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);
                    }
                });
Comments