问题
I want to make my PDF document protected by not allowing fill in and copy from it. I am using iTextSharp for this. I have following code:
PdfReader reader = new PdfReader(document, System.Text.Encoding.UTF8.GetBytes(PASSWORD));
using (MemoryStream ms = new MemoryStream())
{
using (PdfStamper stamper = new PdfStamper(reader, ms))
{
stamper.SetEncryption(
null,
Encoding.ASCII.GetBytes(PASSWORD),
PdfWriter.ALLOW_PRINTING,
PdfWriter.ENCRYPTION_AES_128);
}
}
reader.Close();
When the document is generated I use that code to encrypt the document. But later when I open the document in Adobe Reader (tested on 9 and 11) and check the 'File > Properties > Security' their are no restrictions applied on fill in and copy of the document and their status is Allowed.
Is there any issue in that code?
回答1:
According to the ITextSharp documentation for PdfStamper, the second parameter to this method is an output stream representing the destination for the encrypted PDF document data. The code you show in the question simply disposes the MemoryStream
after you setup the encryption so any changes this code could apply to your PDF document will never be saved to disk or otherwise be available outside your application.
来源:https://stackoverflow.com/questions/21213849/encrypt-pdf-document-using-itextsharp