如何在node js中生成仅第一页的拇指pdf文件

问题描述 投票:0回答:1

当我上传多页 pdf 文件然后多次生成缩略图时,我遇到问题。

我的代码如下

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

如何设置只生成一页缩略图。

javascript node.js pdf socket.io
1个回答
4
投票

我使用 GraphicsMagick 生成 Pdf 文件的缩略图。

var gm = require('gm');
var image = random() + '.png';
var pathToFile = path.join(__dirname, req.files[i].path);
var 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);
        }
    }
);
© www.soinside.com 2019 - 2024. All rights reserved.