Friday, 17 December 2021

azure function to convert pdf to image in node.js?

I am trying to write an Azure function to convert pdf to image in Node.js, but not getting success. Writing directly in azure portal. Using out of the box pdf-poppler package. Here sourcepdf and targetimage are my blob containers.

Below is the code,

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");     

};

Any suggestions,



from azure function to convert pdf to image in node.js?

No comments:

Post a Comment