I know it’s possible to create a PDF with annotations on it that can’t be edited without knowing a password. How would one accomplish that using PDFNet? We have the annotations writing out, and they are locked by default. However, you can simply turn off the lock in Acrobat without any special password or anything.
Thanks - Chris
If you look at the EncryptionTest sample code, you can see how to add a password to a PDF, and also how to specify the permissions, such as annotation editing, using StdSecurityHandler.SetPermission method.
You can also set flags directly on specific annotations, though this would have less “security” then the above way. Some of the these flags specify ReadOnly for instance.
Thanks Ryan! I’ll take a look at that.
I appreciate the help!
Note that PDF security is based on ‘trust’ model your users will always be able to go around permissions (if they really want to).
Another option (that is a bit harder to tamper with) would be to flatten annotations by merging them to PDF content stream (e.g. annot.Flatten(page) or doc.FlattenAnnotations()).
If we were to merge them to a content stream, is there any way to still maintain the metadata?
By Metadata I assume you mean annotation related information, such as author, last modified date, etc?
That stuff all gets erased when flattening, but you can store it in the PDF before flattening so it is not lost, but it would become hidden data that only you know about, and would no longer be tied to the appearance of the annotation.
To store arbitrary data in a PDF see the following.