title: How can I lock a PDF document after signing it?
body: <p>Adobe Acrobat has the option to lock the PDF document after signing it. This changes the document permissions so that Acrobat does not offer signing the document again or modifying annotations or forms. This seems like a reasonable action to do after a document has been signed for review by multiple entities and finally for release by someone responsible.</p>
  
  <p>iTextSharp can also sign documents, and it can also add further signatures to an already signed document. iTextSharp basically also can set the document's permissions, but somehow I can't get it to set the same permissions as Acrobat X Pro does. I set the following permissions:</p>
  
  <ul>
  <li>PdfWriter.ALLOW_COPY</li>
  <li>PdfWriter.ALLOW_DEGRADED_PRINTING</li>
  <li>PdfWriter.ALLOW_PRINTING</li>
  <li>PdfWriter.ALLOW_SCREENREADERS</li>
  </ul>
  
  <p>I do not set the following permissions (which should be all else):</p>
  
  <ul>
  <li>PdfWriter.ALLOW_ASSEMBLY</li>
  <li>PdfWriter.ALLOW_FILL_IN</li>
  <li>PdfWriter.ALLOW_MODIFY_ANNOTATIONS</li>
  <li>PdfWriter.ALLOW_MODIFY_CONTENTS</li>
  </ul>
  
  <p>Anyway, after saving a document like that, I see the following permissions in Acrobat X Pro:</p>
  
  <ul>
  <li>Printing: Allowed (OK)</li>
  <li>Modifying document: Not allowed (OK)</li>
  <li>Assembly: Not allowed (OK)</li>
  <li>Copy contents: Allowed (OK)</li>
  <li>Screen reader: Allowed (OK)</li>
  <li>Remove pages: Allowed (NOT OK)</li>
  <li>Annotate: Allowed (NOT OK)</li>
  <li>Fill in forms: Allowed (NOT OK)</li>
  <li>Sign: Allowed (NOT OK)</li>
  <li>Create templates: Allowed (unknown)</li>
  </ul>
  
  <p>I'm not using encryption because that is only possible before putting the first signature. Also, I don't really want to use it because a) it's basically useless without a viewer password and b) Acrobat doesn't do it either when locking a document after signing.</p>
  
  <p>My code is based on the iSafePDF project (open-source on Codeplex) which is using PdfStamper in some way on an existing document.</p>
  
  <p>My iTextSharp version is 5.2.1. The latest version has incompatible API changes that I didn't resolve yet.</p>
  
  <p>So how can I achieve the same result as with Acrobat?</p>
  
  <p>(I'm aware that my application will still be able to sign the document because it doesn't care for the existing permissions. But at least other Acrobat users should see the "intended permissions" correctly.)</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I have further investigated the issue and it seems to come from here: The permissions can only be set through the PdfStamper.SetEncryption method, as its 4th parameter. But calling this method together with appending a signature leads to the following DocumentException: "Append mode does not support changing the encryption status." I haven't seen a method that sets permissions but not encryption. Is this the problem? Does iTextSharp simply not support what's actually possible?</p>