iText disable printing/Copying/Saving

2019-01-20 06:50发布

问题:

I wrote a servlet to serve PDF using iText. Is there any way to disable printing/Copying/Saving from the browser end?

回答1:

Here's a thread that provides the relevant magic API invocation. The idea is that you have to encrypt the PDF in order to protect various user operations.

PdfReader reader = new PdfReader("my-old-file.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("my-new-file.pdf"));
stamper.setEncryption("my-owner-password".getBytes(), "my-user-password".getBytes(),
    PdfWriter.AllowPrinting | PdfWriter.AllowCopy, PdfWriter.STRENGTH40BITS);
stamper.close();


标签: pdf itext