Reputation: 31
I have a PDF file in S3. eg. original.pdf
please help me
const AWS = require('aws-sdk');
const PDFLIB = require('pdf-lib');
const s3 = new AWS.S3();
exports.handler = (event,context,callback) => {
let params = {
Bucket : 'bucket-name',
Key : 'key'
};
s3.getObject(params,(err,data)=>{
if(err){
console.log(err,err.stack);
}else{
console.log(data);
}
});
const pdfDoc = PDFLIB.create();
}
i think i made step 1 and then i want to generate a new pdf for copying the original pdf.
but in lambda there is an error
Response:
{
"errorType": "TypeError",
"errorMessage": "PDFLIB.create is not a function",
"trace": [
"TypeError: PDFLIB.create is not a function",
" at Runtime.exports.handler (/var/task/test2.js:20:27)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
]
}
Upvotes: 0
Views: 1657
Reputation: 7770
You need to extract the PDFDocument
while requiring pdf-lib
. check the documentation for more details. the code will be like this
const AWS = require('aws-sdk');
const { PDFDocument} = require('pdf-lib');
const s3 = new AWS.S3();
exports.handler = (event,context,callback) => {
let params = {
Bucket : 'bucket-name',
Key : 'key'
};
s3.getObject(params,(err,data)=>{
if(err){
console.log(err,err.stack);
}else{
console.log(data);
}
});
const pdfDoc = PDFDocument.create(); // this is a async function as per documentation so need to await it or use then after that.
}
Hope this works. Note that create
method is async as per documentation.
Upvotes: 1