azure函数将pdf转换为node.js中的图像?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了azure函数将pdf转换为node.js中的图像?相关的知识,希望对你有一定的参考价值。
我正在尝试编写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
的字符串。它将在功能文件夹下创建图像。
以上是关于azure函数将pdf转换为node.js中的图像?的主要内容,如果未能解决你的问题,请参考以下文章
如何将图像转换为 Base64 字符串,并转换回图像,保存到 azure blob
从 Node.js 函数访问 Azure Synapse Analytics