title: Disallow editing but allow page extraction in Java iText / PDF
body: <p>I'm using iText to generate PDF files.  I want to disallow editing of the PDF, but allow the reader to extract pages. Here's my code to set encryption:</p>
  
  <p><code>writer.setEncryption(null, null, 0xffffffff,  PdfWriter.STANDARD_ENCRYPTION_128);</code></p>
  
  <p>The third parameter specifies permissions.  I'm using 0xffffffff instead of the individual iText flags ALLOW_PRINTING etc. This will ask iText to enable everything.  But this is what I get in the PDF file:</p>
  
  <p><img src="https://i.stack.imgur.com/B127m.png" alt="enter image description here"></p>
  
  <p>I should think I should be allowed to enable extraction but disable editing, but am not certain.  Here are the permissions bits per Adobe:
  <img src="https://i.stack.imgur.com/ZXuTM.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/SwiR9.png" alt="enter image description here"></p>
  
  <p>(From <a href="http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf" rel="noreferrer">here</a>, but be warned it's 30 meg)</p>
  
  <p>So turn off bits 6 and 11 but leave on the others (especially bits 5 and 10), and that would turn off editing but allow extraction.  In any case, by specifying 0xffffffff I would think that everything would be allowed; but instead everything <em>except</em> extraction is allowed.</p>
  
  <p>I've skimmed the iText source code for setting permissions and don't see anything that would cause this.  Here is the relevant code from PdfEncryption.setupAllKeys:</p>
  
  <pre><code>permissions |= (revision == STANDARD_ENCRYPTION_128 || revision == AES_128 || revision == AES_256) ? 0xfffff0c0
          : 0xffffffc0;
  permissions &amp;= 0xfffffffc;
  </code></pre>
  
  <p>The first line is doing an OR and so wouldn't remove any permissions; the second line is setting the two right-most bites to 0, per the PDF specification.</p>
  
  <p>I'm wondering if it's an iText thing, a PDF thing or if I'm doing something else wrong.</p>
  
  <p>Thanks</p>