title: Easiest way to detect that a PDF is encrypted with PHP
body: <p>I'm trying to find the best way to <em>detect</em> that a given PDF is encrypted with PHP. I don't need to decrypt it or edit it or anything like that. The idea is to simply provide an error message to a user if they upload an encrypted PDF.</p>
  
  <p>Most of the PDF parsing libraries for PHP that are out there seem to require the entire PDF be read into memory in order to do the parse. For my purpose, reading the entire PDF into memory is unacceptable as the PDF's I am dealing with may be tens if not hundreds of megabytes large.</p>
  
  <p>Shelling out to <code>pdfinfo</code> is not a great option (as I don't like firing up a new process to do this) but that is the solution if there is no other options. I don't know enough about the binary structure of a PDF to even write enough of a parser to detect this so <code>pdfinfo</code> may be the only choice.</p>
  
  <p>TL;DR is there an easy way that is pure PHP (no C extensions) to detect if a PDF is encrypted (aka password protected) that does <strong>not</strong> read the entire thing into memory?</p>