I am new to AWS. Can anyone tell me how to integrate PDFFiller using AWS lambda. I have seen one url. enter link description here
It is very easy to understand. But I don't know how to integrate. I did R&D but didn't get any urls. Can anyone provide some solutions or urls.
Thanks in advance.
See Building Lambda functions with NodeJs
We can deploy the lambda with dependencies as follows
1 - Initialise the Node.js Project
npm init
2 - Install the PdfFiller package
npm install pdffiller --save
3 - Write your index.js file
const pdfFiller = require('pdffiller');
exports.handler = async function (event, context) {
const sourcePDF = 'sample.pdf';
var destinationPDF = "/tmp/test_complete.pdf";
var data = {
"demo" : "demo-val"
};
pdfFiller.fillFormWithOptions( sourcePDF, destinationPDF, data, true,"/tmp",function(err) {
if (err) throw err;
console.log("In callback (we're done).");
});
// TODO implement
const response = {
statusCode: 200,
body: "success",
};
return response;
};
4 - Make a zip
You'll have project structure as
~/my-function
├── index.js
└── node_modules
├── pdffiller
Make your entire project as zip (should include node_modules)
5 - Deploying
And finally you can deploy it. See how to deploy as zip
sourcePDF : Currently, the source pdf has been put within the project itself. This is not a perfect method; you may load it from another source, such as s3, external storage, etc.
destinationPDF , /tmp as prefix : The Lambda execution environment provides a file system for your code to use at /tmp
. This space has a fixed size of 512 MB
. You can attach file system with your lambda when you need to store the destination pdf See. Or another sources such as s3.
Why used fillFormWithOptions
: As the package pdffiller
creating a temporary pdf file,(see index.js file) unlike with the other fie system,lambda uses /tmp for storing the files (without any file-system attachment).
It is necessary to mention the temporary pdf generate path with lambda. Else, the execution will fail at here, as it couldn't be able to create the temp pdf file.
Reference Links :
Hope this helps