azure函数将pdf转换为node.js中的图像?

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

我正在尝试编写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");     

};

任何建议,

javascript azure azure-functions azure-storage-blobs
1个回答
0
投票

下面是我的工作代码:

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.functionDirectoryout_prefix可以是像output的字符串。它将在功能文件夹下创建图像。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.