/pdf-tiny

:crab: Rust wrapper around :ghost: GhostScript to reduce the size of PDFs

Primary LanguageRustApache License 2.0Apache-2.0

pdf-tiny

🦀 Rust wrapper around 👻 GhostScript to reduce the size of PDFs

Usage

pdf-tiny --path input_file.pdf

The output file (the smaller version of the PDF) is written to the same directory as the input file, appending _tiny to the filename.

Requirements

Requires GhostScript be installed. Further requires GhostScript be installed within C:\Program Files\gs (using the default installation options). If the installation path of GhostScript is something other than C:\Program Files\gs then adjust the Rust code accordingly.

Installation

⚠️ Only run the below if you trust this code to be compiled on your machine! ⚠️

cargo install --git https://github.com/curtisalexander/pdf-tiny

How Is This Built?

This is a 🦀 Rust wrapper around a set of options to run 👻 GhostScript from the command line.

The file path to GhostScript is assumed to start with C:\Program Files\gs and is glob matched to ignore the version number in order to identify the gswin64c.exe executable. Then xshell is utilized to execute the program.

The GhostScript incantation is the following. Note that the input file is taken from the command line and the output file has _tiny appended to the filename.

gswin64c.exe -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output_file.pdf input_file.pdf

Compatibility

pdf-tiny only works on Windows due to hard coding the filepath for GhostScript. It could easily be adapted for other operating systems.

Why Build This?

  • Opportunity to experiment with xtask
  • I dislike large PDFs — they crash my printer

Inspired By

SmallerPDF by crissNb