Compress PDF files using GhostScript and Python
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
- 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!








