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

PDF file is not encrypted #503

Open
pallavinishanth opened this issue Apr 21, 2023 · 0 comments
Open

PDF file is not encrypted #503

pallavinishanth opened this issue Apr 21, 2023 · 0 comments
Labels
type: bug Existing feature doesn't work correctly

Comments

@pallavinishanth
Copy link

Describe the bug
I am not able to password protect the pdf file, I just want owner password protected.

Here is the sample snippet of code that I wrote to password protect existing pdf file.

PDFBoxResourceLoader.init(context);
AccessPermission permission = new AccessPermission();
permission.setCanExtractContent(false);
permission.setCanModify(false);
permission.setCanModifyAnnotations(false);
permission.setCanPrint(true);
permission.setReadOnly();
StandardProtectionPolicy spp = new StandardProtectionPolicy("password" , "" , permission);
spp.setEncryptionKeyLength(128);
spp.setPermissions(permission);
BouncyCastleProvider provider = new BouncyCastleProvider();
Security.addProvider(provider);
try {
PDDocument pdfDoc = PDDocument.load(pdfFile);
pdfDoc.protect(spp);
pdfDoc.save(pdfFile);
pdfDoc.close();
} catch (IOException e) {
Log.e(Nimbus.TAG, "Exception while loading pdf file ", e);
}

Not sure why the pdf is not getting encrypted, let me know if anything is wrong in the above code snippet. Any help is much appreciated.

Environment details:

  • PdfBox-Android version: [e.g. 2.0.27.0]
  • Android API version: [e.g. API 33]
@pallavinishanth pallavinishanth added the type: bug Existing feature doesn't work correctly label Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Existing feature doesn't work correctly
Projects
None yet
Development

No branches or pull requests

1 participant