menuimage

Description

Usage

Options

Dependencies

Changelog

Download

My_Other_Sites

My_Programs

Comments

pdf-compress v0.5 [16 Nov 2017] - by Dominic

Description

Compress an overlarge pdf file. Use case is a file generated by scanning with unnecessarily high resolution and/or color. The aim is to produce a file that is black-and-white but still legible and much smaller. It does not always succeed (result may not be legible, or may be larger), but when it works it can dramatically reduce file sizes (90%+) while maintaining good legibility. This is achieved by conversion to 1-bit pixel mapping, so is typically most effective for black text on a white background.

If destination path/file is unspecified pdf-compress.sh will create a file in the same location as source, with -1 suffixed to the filename (before .pdf extension). If destination is a directory then the created file will have the same name as the source file.

Using a different resize percentage (default 200) does not affect the physical size of the pages in the destination file, but will alter the file size and quality as well as the speed of operation - you may have to experiment to get the best balance with each original (or type of such). Note that the use of high figures (say 300+) is exponentially slower and can cause pdf-compress.sh to run out of memory.

Specify additional options to be passed to the image-magick convert operation within pdf-compress.sh by using -p; for instance, to hide a watermark try -p '-white-threshold 60%'.

Usage

./pdf-compress.sh [options] source_path/filename [destination_path[/filename]]

Options

-h - show this help and exit
-l - show changelog and exit
-n - negative result (black becomes white and vice-versa) - sometimes needed to correct auto-negation
-p - specify extra parameters for convert e.g. -p '-white-threshold 60%'
-q - quiet output
-r num - resize percentage (1+, default 200; note that use of high figures say 300+ will be exponentially slower and can cause out-of-memory failures)
-v - be more verbose
-t path - directory to use for temporary files, which can be large (default: /tmp)
-y - overwrite destination file if it already exists

Dependencies

bash 4+, image-magick, ghostscript (gs)

Changelog

0.5 [16 Nov 2017] - negate by default (-n to non-negate), default resize 200 not 100, add -p option
0.4 [23 Apr 2017] - add -n (negative) option
0.3 [16 Oct 2016] - fix for temporary file deletion, make temporary filenames unique
0.2 [21 Sep 2016] - lots of tweaks
0.1 [20 Sep 2016] - initial version

Download pdf-compress.sh

My Other Sites

My Programs

Here is a selection of some (other) programs I have written, most of which run from the command line (CLI), are freely available and can be obtained by clicking on the links. Dependencies are shown and while in most cases written for a conventional Linux server, they should run even on a Raspberry Pi, and many can run under Windows using Cygwin. Email me if you have problems or questions, or if you think I could help with a programming requirement.

Backup Utilities

Debian/Ubuntu kernel and LVM Utilities

Dellmont / Three / Giffgaff / Vodafone - VoIP and Mobile Phone Account Utilities

Miscellaneous Programs

Comments

Spiv 14 Oct 2016, 16:02
Hi Dominic,
thank you for this nice program!

How do I actually install and then use it on Ubuntu 16.04 (I am a bit of a novice....)?

Keep smiling
Spiv
*Name:
Email:
Hide my email
*Text:
 
Powered by Scriptsmill Comments Script