我正在尝试编写Azure函数以将pdf转换为Node.js中的图像,但没有成功。直接在Azure门户中编写。使用开箱即用的pdf-poppler软件包。这里的sourcepdf和targetimage是我的Blob容器。
下面是代码,
const pdf = require('pdf-poppler');
const path = require('path');
const fs = require('fs');
const URL = require('url');
const storage = require('azure-storage');
module.exports = async function (context, myBlob) {
context.log(context.bindingData.blobTrigger);
//context.log(context.bindingData.uri);
let file = '/sourcepdf/sample.pdf';
let opts = {
format: 'jpeg',
out_dir: '/targetimage/sample.jpg',
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);
})
//context.log("JavaScript blob trigger function processed blob \n Blob:", context.bindingData.blobTrigger, "\n Blob Size:", myBlob.length, "Bytes");
};
任何建议,
下面是我的工作代码:
context.log('JavaScript HTTP trigger function processed a request.');
let file = 'D:\\home\\site\\wwwroot\\nodejs.pdf'
let opts = {
format: 'jpeg',
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);
})
[除此之外,您可以定义输出目录和文件名前缀,例如out_dir
可以是context.executionContext.functionDirectory
,out_prefix
可以是像output
的字符串。它将在功能文件夹下创建图像。