Sitemap

Compress PDF files using GhostScript and Python

1 min readJun 13, 2025

--

Are you sceptical about using apps or tools to compress your PDF files?

The solution is simple. Use software tools and technologies to your benefit.

Write a simple Python script and a Ghost script.

Follow these steps

  1. Install GhostScript

On Windows:

Download and install from https://ghostscript.com/releases/gsdnld.html

Add the Ghost script to your PATH. Provide the complete path until the bin folder.

Get Jayabalambika R’s stories in your inbox

Join Medium for free to get updates from this writer.

For example: It could be like this C:\Program Files\gs\gs10.01.2\bin

2. Check if GhostScript is accessible in the command prompt

This will print the version if GhostScript is installed properly.If you get 'gswin64c' is not recognized thePATH is not correctly set.

3. Now write the Python code to call the correct subprocess

4. Run the above python code.

5. Navigate to the output folder in your code, and the compressed file is generated in that folder. The program prints the above in the command prompt

Compressed file size: 1.64 MB
Compression successful and under target size.

Happy Experimenting!

--

--

Jayabalambika R
Jayabalambika R

Written by Jayabalambika R

Linkedin account: www.linkedin.com/in/mypage1 PGD in AI/ML AppliedRoots and UoH, Full Stack Programmer,HuggingFace Open Source library contributore