Hopding/pdf-lib

Encrypt PDF

Shanmugapriya-R805 opened this issue · 0 comments

What were you trying to do?

Encrypt PDF

How did you attempt to do it?

pdfDoc.encrypt({
userPassword: 'abcd',
ownerPassword: '1234',
permissions: { modifying: true },
});

What actually happened?

Error creating PDF: TypeError: pdfDoc.encrypt is not a function

What did you expect to happen?

Need to create password protected pdf

How can we reproduce the issue?

async function createPasswordProtectedPDF() {
const pdfDoc = await PDFDocument.create();
const page = pdfDoc.addPage();
page.drawText('Creating PDFs in JavaScript is awesome!', {
x: 50,
y: 700,
});

  pdfDoc.encrypt({
    userPassword: 'abcd',
    ownerPassword: '1234',
    permissions: { modifying: true },
  });
 
const pdfBytes = await pdfDoc.save({ useObjectStreams: false });
fs.writeFileSync('sample.pdf', pdfBytes);

}

function createPwdProtectedPDF(req, res) {
createPasswordProtectedPDF()
.then(() => console.log('Password-protected PDF created!'))
.catch(err => console.error('Error creating PDF:', err));
}

Run the above code in node environment

Version

"pdf-lib": "^1.17.1",

What environment are you running pdf-lib in?

Node

Checklist

  • My report includes a Short, Self Contained, Correct (Compilable) Example.
  • I have attached all PDFs, images, and other files needed to run my SSCCE.

Additional Notes

No response