I need to put a password protection to PDF files using ghostscript in php.
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.
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.
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:
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");
pdf_reference17.pdf
you should find one somewhere. Pages 120-124 describe the various permissions. - StackOverflow question and answer at the URL below specifically describe how to build/unpack the permissions bit field: #51116241 – Inadvertent