The order of operations is always Encrypt (first), Reader Extend (second), (and if you are also certifying the document) Certify (third) (when you certify a document, an "Author" digital signature is applied to the document).
There is no way around this, the document must be encrypted first, then RE applied.
oh, I can add RE to an encrypted document? that is good to know. Plus I did not realize that I can add RE with the Java API.
Thank you very much for your answer, this helped a lot.
I implemented encryption and reader extension and I get the following error when I add reader extensions to my formerly encrypted document:
Caused by: com.adobe.livecycle.readerextensions.client.ProcessingException: ALC-RES-001-022: The input PDF document is encrypted and needs to be unlocked for this operation.
When I do it the other way round, I get the error message I described above. So, how can I encrypt and reader extend my document?
There is a thread here but it does not solve my problem.
Thanks in advance for your help.
Problem solved, you have to unlock the pdf before adding reader extensions.
There is a difference between unlocking and removing encryption. When you unlock a pdf you just open it up for some operations. After that (precisely: when you call the getInputStream() method) it will be locked (encrypted) again.
When you add encryption to a document, it is added when you persist the doc somehow. From the document's point of view persisting means calling the getInputStream() method. That method is used when you copy the document to a file. This means that you can encrypt a document and add reader extension right after that without unlocking the pdf. When you save it afterwards the encryption wil be applied.
When you encrypt a document, save it and then add RE, you have to unlock it first, because the encryption is already applied.
I hope this helps someone to save the time I needed to figure that out.