如何使用Azure Web应用程序上的Nodejs将PDF转换为图像

时间:2017-05-31 08:41:17

标签: node.js azure azure-web-sites

我正在尝试使用Nodejs将pdf文件转换为png文件。通常,我可以在本地使用Imagemagick模块来完成。但是,我做了一些search,发现我无法在Azure Web应用上使用ImageMagick或Graphics Magic等第三方应用。

2 个答案:

答案 0 :(得分:2)

尝试 App Service on Linux ,默认情况下,ImageMagick库中包含内置Docker镜像。开箱即用。

这是他们用于节点的基本图像:
https://github.com/docker-library/buildpack-deps/blob/master/jessie/Dockerfile#L25

这是我写的一个例子: https://github.com/snobu/gifinator

如果你真的真的想要在Windows上运行ImageMagick(虽然为了你自己的理智我会反对),请查看我为App Service写的这本指南 - 它适用于PHP,但应该是一个好的节点的起点:
https://github.com/snobu/php-imagick-webapps

答案 1 :(得分:0)

有一个 PDF-Poppler 库

https://www.npmjs.com/package/pdf-poppler

示例代码

const path = require('path');
const pdf = require('pdf-poppler');
 
let file = 'C:\\PDF2TIFF\\sample.pdf'
 
let opts = {
    format: 'png',
    out_dir: path.dirname(file),
    out_prefix: path.basename(file, path.extname(file)),
    page: null
}
 
pdf.convert(file, opts)
    .then(res => {
        console.log('Successfully converted');
    })
    .catch(error => {
        console.error(error);
    })