title: Password protected PDF using Ghostscript
body: <p>I need to put a password protection to PDF files using ghostscript in php.</p>
  
  <p>These files will be uploading to server using simple form (I don't need any help with this), but they won't have any protection at first. So I want to put password protection to them using exec function and ghostscript in it. But I couldn't find anywhere what ghostscript query should be like.</p>
  
  <p>For example, I have a PDF file called File.pdf. I upload it and then I need to put protection to it and call it File_protected.pdf.</p>
  
  <p>I was trying to do it like this but '.ps' file weights too much and there is no password in the final File_protected.pdf:</p>
  
  <pre><code>exec("gs -dNOPAUSE -dBATCH -sDEVICE=pswrite -sOutputFile=File.ps File.pdf");
  exec("gs -dNOPAUSE -dBATCH -sPDFPassword=password -sDEVICE=pdfwrite -sOutputFile=File_protected.pdf File.ps");
  </code></pre>