Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encrypt PDF #1680

Open
2 tasks done
Shanmugapriya-R805 opened this issue Sep 20, 2024 · 1 comment
Open
2 tasks done

Encrypt PDF #1680

Shanmugapriya-R805 opened this issue Sep 20, 2024 · 1 comment

Comments

@Shanmugapriya-R805
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
@Shanmugapriya-R805 and others