-
Notifications
You must be signed in to change notification settings - Fork 360
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
Add PDF properties like owner, security... #30
Comments
OK, I've just added a method to get the PDDocument so you can protect it. The code will look something like: PdfRendererBuilder builder = new PdfRendererBuilder();
// set options on builder...
PdfBoxRenderer r = builder.buildPdfRenderer();
AccessPermission p = new AccessPermission();
p.setCanAssembleDocument(false);
p.setCanExtractContent(true);
p.setCanExtractForAccessibility(true);
p.setCanFillInForm(true);
p.setCanModify(false);
p.setCanModifyAnnotations(true);
p.setCanPrint(false);
p.setCanPrintDegraded(false);
p.setReadOnly();
PDDocument doc = r.getPdfDocument();
doc.protect(new StandardProtectionPolicy("ownerPassword", "userPassword", p));
r.layout();
r.createPDF();
r.cleanup(); You'll probably have to add the Bouncy Castle dependencies. The protection happens when the document is saved. You can set the title, author, subject and keywords in the html: <html>
<head>
<title>The Great American Novel</title>
<meta name="author" content="Herbit"/>
<meta name="subject" content="A tale of mice and men"/>
<meta name="keywords" content="pet, mice, novel"/>
</head>
<body>
....
</body>
</html> |
Great thanks ! |
Thanks Dan. I know there is an issue on this already, but more examples would be very helpful -- I had no idea how to dot this prior to your post. |
I tried to protect my PDF document using the AccessPermission / ProtectionPolicy approach @danfickle suggested. Unfortunately, the document is not protected unless i set everything to false This does work: --> The document prevents me from copying selected text and printing etc. This does not work: --> I am able to do anything with the document. Copying selected text is not being prevented. Does anybody know what i am missing out? |
* Remove unused, deprecated isSupportsSelection() Signed-off-by: XSpielinbox <[email protected]> * Remove broken config to disable doclint Signed-off-by: XSpielinbox <[email protected]> * Switch to HTTPS in license URl Signed-off-by: XSpielinbox <[email protected]> --------- Signed-off-by: XSpielinbox <[email protected]>
Is it possible to add PDF properties ?
I mean properties like owner, title, subject, security...
The text was updated successfully, but these errors were encountered: