title: How to identify if a PDF file contains form fields
body: <p>We allow users to upload PDF documents for us to store. We warn the users that the PDF must be flattened before uploading, but many still upload PDF documents that contain form fields. We want to prevent this by validating the PDF file before uploading to our storage.</p>
  
  <p>We are using iText-5.1 to read the file as a byte[] and open it with PdfReader. We then extract the fields with AcroFields() and test for existence. Currently the getFields().size() is always returning 0 <em>[see code below]</em>, even with a test PDF that I know contains form fields.</p>
  
  <pre class="lang-java prettyprint-override"><code>PdfReader reader = new PdfReader(bytes);
  AcroFields fields = reader.getAcroFields()
  boolean hasFormFields = 
     (fields != null &amp;&amp; fields.getFields() != null &amp;&amp; fields.getFields().size() &gt; 0);
  if (hasFormFields) {
     // Report Error to User - throw exception, etc.
  }
  </code></pre>
  
  <p>I would expect the getFields().size() to be larger than 0 when the PDF contains form field elements. Is there some other way to identify form fields using Java and iText?</p>