pdf with the /go/pdf Command

/go/pdf finds PDF files and recompresses each one with Ghostscript. A file is replaced only if the compressed copy is smaller, so no PDF ever gets bigger. Each file keeps its original timestamps. You can point it at: Every admin action in GoAdmio has a matching /go/ command, so anything you can click you can also script.

Quick start

# Compress every PDF in a domain's www folder
/go/pdf example.com

Options

Target

The first argument says where to look. The command uses the first rule that matches.

Target Meaning
An existing file or folder path That file, or every PDF inside that folder, including subfolders.
all Every PDF under /home, including mail folders and anything else stored there, not only www folders.
A domain name The PDFs in /home/<domain>/www.

If nothing matches, the command prints <target> does not exist and exits with status 1.

Other options

Option Required Default Notes
prefix No — The second argument. Only PDFs whose names start with it are processed, for example a matches a1.pdf. Case-sensitive. Ignored if it starts with --.
--screen No Off Uses Ghostscript’s /screen setting (smallest files, lowest image quality) instead of /ebook.
--md5 No Off Splits the work into 16 background runs by first character of the file name. See The --md5 option.
--skip log No Off Used with --md5. Skips any starting character that already has a log file. Write it as two words.

Only files named *.pdf in lowercase are found. Files ending in .PDF are ignored.

Examples

# Every PDF in a domain's www folder
/go/pdf example.com

# Only PDFs whose names start with "a"
/go/pdf example.com a

# Smaller files, lower quality
/go/pdf example.com --screen

# One folder
/go/pdf /home/example.com/www/uploads

# A single file
/go/pdf /home/example.com/www/uploads/report.pdf

# Every PDF on the server
/go/pdf all

# A large site, in 16 background runs
/go/pdf /home/example.com/www --md5

# Run the missing runs again, keeping those that already have a log
/go/pdf /home/example.com/www --md5 --skip log

Output

For each compressed PDF the command prints one line. The percentage is the new file’s size compared with the original, so a lower number means more savings.

[1/12] Resizing /home/example.com/www/docs/a.pdf (42%)...
[2/12] Resizing /home/example.com/www/docs/b.pdf (Same Size)...

Message Meaning
Resizing <file> (<n>%)... The compressed copy was smaller and replaced the original.
Resizing <file> (Same Size)... The compressed copy was not smaller (the same size or larger), so the original was kept.
<target> does not exist The first argument matched nothing. Exit status 1.

When only one file is found, the [n/total] prefix is left out. If no PDFs are found, the command prints nothing.

Log

Each run appends one line to /var/log/go/pdf.log:

[Nov 21 12:00:00]# pdf example.com

With --md5, each background run also writes its own log, described below.

See the full reference at /go/pdf and the GoAdmio command index.

GoAdmio is free and open source, with no license fees and no account limits. Read the GoAdmio docs, or see why it is a free cPanel alternative at goadmio.com.

By:

Posted in:


Leave a Reply

Your email address will not be published. Required fields are marked *