How to use GhostScript for Windows to repair damaged PDF files

My PDF file is corrupted, then after searching the web I found a good thread here. Since I hadn't gswin32c on my Windows 7 x86 system I installed it from here. Now I have it on my system and ran it now! :) But my problem is that how to use the commands written there as follows:

gswin32c.exe ^
  -o repaired.pdf ^
  -sDEVICE=pdfwrite ^
  -dPDFSETTINGS=/prepress ^
   corrupted.pdf

Solution 1:

How do I use the following commands:

gswin32c.exe ^
  -o repaired.pdf ^
  -sDEVICE=pdfwrite ^
  -dPDFSETTINGS=/prepress ^
   corrupted.pdf

Note that the above is a single command. The ^ character is an escape character, allowing the command to be split across multiple lines (it is escaping the <eol> characters).

So it could be written as:

gswin32c.exe -o repaired.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress corrupted.pdf

To run this command:

  1. Open a cmd shell

  2. Change directory to the location of the PDF file:

     cd c:\PathToMypdf
    
  3. Run the following command:

     c:\PathToGswin\gswin32c.exe -o repaired.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress corrupted.pdf
    

Notes:

  • If PathToMypdf contains spaces then the directory needs to be quoted:

     cd "c:\PathToMypdf"
    
  • if PathToGswin contains spaces then the command needs to be quoted:

     "c:\PathToGswin\gswin32c.exe" -o repaired.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress corrupted.pdf
    

C:\Program is not recognized as an internal or external command, operable program or batch file

My pdf file with the name p2.pdf is in this diretory: C:\Users\Me\Desktop\Attach.

And the gswin32c.exe is in this directory: C:\Program Files\gs\gs9.09\bin

When I run this command:

C:\Program Files\gs\gs9.09\bin\gswin32c.exe -o repaired.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress p2.pdf

I get the following error "C:\Program" is not recognized as an internal or external command, operable program or batch file.

What part is wrong please?

You need to run the following commands:

cd C:\Users\Me\Desktop\Attach
"C:\Program Files\gs\gs9.09\bin\gswin32c.exe" -o repaired.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress p2.pdf

Notes:

  • The "s are required because the path C:\Program Files\gs\gs9.09\bin\ contains spaces.