Friday, March 07, 2014

Remove PDF password and restrictions using Ghostscript via drag and drop

I deal with and process lots of PDFs. However, sometimes the security settings of the PDF documents cause trouble.

There are several online websites available to remove these restrictions. Most offline tools cost more than 20 dollars. Actually we can do this ourselves via drag and drop, if Ghostscript is installed, free of charge.
  1. If you don't have Ghostscript installed, download it from http://www.ghostscript.com/. It is free.
  2. Save the following code as a .cmd file.
    @echo off
    echo.
    echo.
    set PATH="C:\Program Files\gs\gs9.07\bin"
    echo **************************************
    echo.
    echo   Start processing, may take a while, please wait.
    echo.
    echo **************************************
    echo.
    echo.
    set filein=%~1
    set fileout=%filein:~0,-4%
    gswin64c -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sPDFPassword= -dPDFSETTINGS=/prepress -dPassThroughJPEGImages=true -sOutputFile="%fileout%_noPW.pdf" "%~1"
  3. Change this line according to the installation directory of the Ghostscript on your machine.

    set PATH="C:\Program Files\gs\gs9.07\bin"
     
  4. Change 'gswin64c' to  ‘gswin32c’ if you install the 32-bit version.
  5. Once the configuration is done, you can drag a password protected PDF to the .cmd file icon, a file without restrictions will be generated in the same folder.
  6. To change the icon of the file, create a shortcut to the .cmd file. The icon of the shortcut can be changed.
  7. If the PDF requires a password to open, then this password must be known to remove restrictions. In this case, the password should be provided to gswin64c via

    -sPDFPassword=YOUR PASSWORD
     
      
%%%
Update: Apri 2015
If you prefer to use software instead of this DIY approach, you may have a look at PDF Restriction Remover, which can be found at http://www.pdfconvertonline.com/pdf-restrictions-remover.html.

19 comments:

  1. Very helpful!!

    ReplyDelete
    Replies
    1. I am happy to find this post very useful for me, as it contains lot of information. I always prefer to read the quality content and this thing I found in you post. Thanks for sharing. combinepdf.net

      Delete
  2. it did not work for me

    ReplyDelete
    Replies
    1. Make sure you install Ghostscript and change the installation folder of Ghostscript accordingly. This approach has been tested in a number of computers without any issue.

      Delete
  3. I had to upgrade from V8.xx to V9.xx to get it to work, but worked properly after that.

    ReplyDelete
  4. Is there a way to loop this thorugh all files in a target directory instead of dragging a single file to the BAT shortcut?

    ReplyDelete
    Replies
    1. Hi, you can do that by some modifications, see
      https://stackoverflow.com/questions/5642021/batch-process-all-files-in-directory
      https://stackoverflow.com/questions/180741/how-to-do-something-to-each-file-in-a-directory-with-a-batch-script

      Delete
  5. Ditto, this was exactly what I was looking for. Thanks for sharing mate.

    ReplyDelete
  6. I had to google "how to create a cmd file" but I figured it out. Thanks for the code!

    ReplyDelete
  7. Great job, very helpful!

    ReplyDelete
  8. This didn't work for me. When I try to open the secured PDF manually from the main GS window to debug the issue (by manually copying MySecured.pdf to the ...gs\gs9.22\bin\ folder, then running gswin64.exe, then entering command "(MySecured.pdf) run") I can see that I get the useful error:
    **** Warning: This file uses and unknown security handler.
    Cannot decrypt PDF file.

    Any other ideas?

    ReplyDelete
    Replies
    1. Just to close this question in case anyone else sees this "issue," the problem occurs when MySecured.pdf contains Adobe's proprietary DRM format, and is apparently (understandably) not resolvable via Ghostscript. See:
      https://ghostscript.com/pipermail/gs-bugs/2013-August/032569.html

      Delete
  9. Worked !! Thank you :)

    ReplyDelete
  10. Try ToolsGround PDF Unlock Tool

    ReplyDelete
  11. Unlock the protected PDF files in the batch with the assistance of Stillbon PDF Unlocker Tool. Users can remove the comment and password restrictions to effortlessly perform the editing, copying, and printing of the PDF files. It is supportable with al the Windows and Mac OS. PDF Unlocker Software is a 100% safe solution to unlock the protected PDF files in the batch. A FREE TRIAL EDITION for the same is also available.

    Explore more details at:- PDF Unlocker Software

    ReplyDelete
  12. I loved as much as you will receive carried out right here. The sketch is attractive, your authored material stylish. nonetheless, you command get bought an impatience over that you wish be delivering the following. unwell unquestionably come more formerly again as exactly the same nearly a lot often inside case you shield this increase.

    ReplyDelete
  13. Have you ever thought about adding a little bit more than just your articles? I mean, what you say is valuable and everything. However think of if you added some great visuals or videos to give your posts more, "pop"! Your content is excellent but with pics and video clips, this blog could undeniably be one of the greatest in its field. Amazing blog!

    ReplyDelete
  14. Hi! What if the pdf document has an expiration date with the inbuilt javascript on adobe reader? possible to remove it too?

    ReplyDelete