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

Add PDF properties like owner, security... #30

Closed
juju35 opened this issue Jul 8, 2016 · 4 comments
Closed

Add PDF properties like owner, security... #30

juju35 opened this issue Jul 8, 2016 · 4 comments

Comments

@juju35
Copy link

juju35 commented Jul 8, 2016

Is it possible to add PDF properties ?
I mean properties like owner, title, subject, security...

@danfickle
Copy link
Owner

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>

@juju35
Copy link
Author

juju35 commented Jul 8, 2016

Great thanks !

@juju35 juju35 closed this as completed Jul 8, 2016
@eschulma
Copy link

eschulma commented Feb 8, 2017

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.

@t-itzel
Copy link

t-itzel commented Aug 4, 2019

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:
AccessPermission accessPermission = new AccessPermission(); accessPermission.setCanExtractContent(false); accessPermission.setCanModify(false); accessPermission.setCanModifyAnnotations(false); accessPermission.setCanPrint(false); accessPermission.setCanPrintDegraded(false); accessPermission.setCanAssembleDocument(false); accessPermission.setCanExtractForAccessibility(false); accessPermission.setCanFillInForm(false); accessPermission.setReadOnly();

--> The document prevents me from copying selected text and printing etc.

This does not work:
AccessPermission accessPermission = new AccessPermission(); accessPermission.setCanExtractContent(false); accessPermission.setCanModify(false); accessPermission.setCanPrint(true);

--> I am able to do anything with the document. Copying selected text is not being prevented.

Does anybody know what i am missing out?

burka pushed a commit to burka/openhtmltopdf that referenced this issue May 3, 2024
* Remove unused, deprecated isSupportsSelection()

Signed-off-by: XSpielinbox <55600187+xspielinbox@users.noreply.github.com>

* Remove broken config to disable doclint

Signed-off-by: XSpielinbox <55600187+xspielinbox@users.noreply.github.com>

* Switch to HTTPS in license URl

Signed-off-by: XSpielinbox <55600187+xspielinbox@users.noreply.github.com>

---------

Signed-off-by: XSpielinbox <55600187+xspielinbox@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants