I am serving a PDF to a browser via a Servlet. I need to disable the "save" and "print" option in the Adobe Reader menu bar while other options like "scroll", "find",... should be preserved. In addition to this, I need to disable the file menu of the browser window in which it is rendered.
I have disabled print and file menu using below code
stamper.setEncryption( null,null, PdfWriter.HideWindowUI, PdfWriter.STRENGTH40BITS); stamper.setViewerPreferences(PdfWriter.HideToolbar);
We need to distinguish two different aspects: printing and saving.
You can encrypt a file and set the permissions in such a way that printing isn't allowed. However: if you only encrypt a document with an owner password, it is very easy to decrypt the document and to remove the restrictions. Encrypting a document with an owner password only works on a psychological level. You indicate that the original producer of the document doesn't want the document to be printed, but on a technical level, it's easy to remove this form of protection.
If you want to avoid that an end users saves a PDF document, you are asking something that is impossible. The only way to avoid that an end user doesn't have a copy of the PDF is by not sending him the PDF. A PDF can't be opened in Adobe Reader without having the actual bytes on a local disk. Even if you would find a workaround to disable saving (for instance in the context of a web application), you'd always find the PDF somewhere in the temp files and people would be able to copy that file as many times as they want.
In your code snippet, you try hiding the toolbar (a viewer preference), but that's not efficient. Whether or not this viewer preference will be respected entirely depends on the PDF viewer. For instance: in Adobe Reader X and later, you have a special widget that appears when you hover over the document. This widget allows users to save the document.
Even with Adobe Reader 9, hiding the toolbar isn't sufficient: if the user chooses the appropriate menu item or hits the appropriate "hot key", the toolbar would appear and they could happily click the Save button. In addition, they could have right-clicked and chosen "Save" as well.
What you need to do is not to prevent saving, but to control the actual use of the PDF and that's where Digital Rights Management (DRM) comes in. DRM however is usually expensive, it also requires a custom PDF viewer. In any case: it's out of the scope as far as iText is concerned.
Click this link if you want to see how to answer this question in iText 5.