【发布时间】:2023-03-12 17:31:01
【问题描述】:
我正在尝试使用 Nodejs 将 pdf 文件转换为 png 文件。通常,我可以通过在本地使用 Imagemagick 模块来做到这一点。但是,我做了一些search,发现我不能在 Azure Web 应用程序上使用 ImageMagick 或 Graphics Magic 等第三方应用程序。
【问题讨论】:
标签: node.js azure azure-web-app-service
我正在尝试使用 Nodejs 将 pdf 文件转换为 png 文件。通常,我可以通过在本地使用 Imagemagick 模块来做到这一点。但是,我做了一些search,发现我不能在 Azure Web 应用程序上使用 ImageMagick 或 Graphics Magic 等第三方应用程序。
【问题讨论】:
标签: node.js azure azure-web-app-service
试试 App Service on Linux,ImageMagick 库默认包含在内置的 Docker 映像中。开箱即用。
这是他们用于 Node 的基本图像:
https://github.com/docker-library/buildpack-deps/blob/master/jessie/Dockerfile#L25
这是我写的一个示例: https://github.com/snobu/gifinator
如果你真的真的想在 Windows 上运行 ImageMagick(尽管为了你自己的理智我建议不要这样做),请查看我为 App Service 编写的这份指南——它适用于 PHP,但应该是一个不错的选择Node 的起点也是:
https://github.com/snobu/php-imagick-webapps
【讨论】:
有一个库 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);
})
【讨论】: