Compress PDFs

Senkusha

Student Council President
gemgemgemgemgemgemgem
Staff member
Administrator
Isekai Society
Top Poster Of Month
Joined
20-Jun-2003
Messages
2,075
Age
51
Gender
Female
So as I add more role playing guides to our Resources section, I've run into a few that are monstrosities.... like Tenchi Universe, was about 1 GB in size. There's no way I'm offering that guidebook to eat up all my bandwidth. So I needed to find a way to reduce its size. There's a number of tools available online that allow you to compress or shrink PDFs... for a conveniently monthly subscription. But I'm only going to need to do this a handful of times.

Enter GhostScript. This is a tool that somebody created that you can run on your own computer. There's both a Linux and Windows version available. I used AI to help me run this program, because it's a little techy.

This is a program designed to be run from your Terminal / Command Prompt / PowerShell. I installed it in the default location C:\Program Files\gs\gs10.08.0\, and you run it from the bin\ sub-directory, and basically, it's program, command switches, output file, input file.

So, using my massive Tenchi RPG, it's currently at 1,379,811 KB (or almost 1.4 GB) I ran the following command:
C:\Program Files\gs\gs10.08.0\bin\gswin64c -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -dNOPAUSE -dBATCH -sOutputFile="D:\Role Playing Games\Big Eyes Small Mouth\Big Eyes Small Mouth 1\Tenchi Universe RPG Resource Book_reduced.pdf" "D:\Role Playing Games\Big Eyes Small Mouth\Big Eyes Small Mouth 1\Tenchi Universe RPG Resource Book.pdf"

The result is a PDF that is only 38,976 KB! Granted, that's a little bigger than the professional compression I got using a free trial (27,741 KB), but I think that's impressive. I could probably dig into all the different command line switches and squeeze the file further, but under 40 MB is satisfactory for me... compared to 1.4 GB!

Making it handy:​

Now, I decided, I'll have to do this a few more times, and it's a lot of work typing all that out in PowerShell. so, I made a script to do that. Furthermore, I added a Right-Click menu within Windows:

Bash:
@echo off
set "GS=C:\Program Files\gs\gs10.08.0\bin\gswin64c.exe"
set "IN=%~1"
set "OUT=%~dpn1_smaller.pdf"

if not exist "%GS%" (
    echo Ghostscript not found at: "%GS%"
    pause
    exit /b 1
)

"%GS%" -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -dNOPAUSE -dBATCH -sOutputFile="%OUT%" "%IN%"
if errorlevel 1 (
    echo Compression failed.
    pause
    exit /b 1
)
echo Created: "%OUT%"
pause

And then here's the Registry addition to make it Right-Click friendly:
Code:
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\SystemFileAssociations\.pdf\shell\CompressPDF]
@="Compress PDF"

[HKEY_CURRENT_USER\Software\Classes\SystemFileAssociations\.pdf\shell\CompressPDF\command]
@="\"C:\\Tools\\compress-pdf.cmd\" \"%1\""

When I'm ready to remove it from my system (maybe never), I'll open the Registry Editor and go to this location: HKEY_CURRENT_USER\Software\Classes\SystemFileAssociations\.pdf\shell and delete the CompressPDF key.

The above command was just a basic one. Sometimes you may run into errors, and there's other options that can be added to the Command Line Swtiches to work through those.
 
Back
Top