How to Encrypt PDF Documents with GhostScript for Free

GhostScript is a powerful tool that Linux users have been playing with for more than a decade. But for the Windows users it is not so much of a familiar name. GhostScript is a command line interpreter for handling, editing, creating and manipulating PostScript (PS) and PDF documents easily. At first it looks very complicated and overwhelming, but once you get the hang of it, it becomes very easy to use. You can use it to extract pages PDF files, convert PDF files into other supported formats, password protect and encrypt files and so on.

If you want to encrypt your existing PDF documents using GhostScript, then you have to issue just one command. Here is how:

  1. First of all, download install GhostScript in your Windows. Make sure to install 32-bit or 64-bit versions of GhostScript depending on the version of your Windows operating system.
  2. Add GhostScript folder to your PATH variable. To do this:
    • press Win+Pause to open System Properties.
    • Click on Advanced System Settings.
    • Click on the Environment Variables button.
    • Select Path variable from under System Variables, click on the Edit button.
    • At the end of existing value, type a semi-colon followed by the path of GhostScript BIN folder (usually something like C:\Program Files\gs\gs9.18\bin).
    • Click on OK to save the settings. Close all the windows opened during these steps.
  3. Open a command prompt and give this command:
    gswin64c -sDEVICE=pdfwrite -sOwnerPassword=PASS -sOutputFile=output.pdf original.pdf

    where PASS is the password of your choice used for encryption, output.pdf is the encrypted output file, and the original.pdf is the input PDF file that you want to encrypt. If you are using the 32-bit version of GhostScript, then command starts with gswin32c instead of gswin64c.Secure PDF Documents with GhostScript

  4. Do not forget to type quit and press Enter to close the GhostScript interpreter. Without this step, the PDF file is not properly generated.
  5. Now you can open the output PDF file in any PDF viewer application and check the document properties to see the security of the document. The document will be shown to have 40-bit RC-4 encryption.Secure PDF Documents with GhostScript

The RC4 cipher is not really very strong cipher for the modern times and is shown to be vulnerable to brute force attacks. GhostScript does not offer higher levels of encryption for the PDF documents. But RC40 is certainly better than nothing as far as the requirement of encrypted PDF documents goes.