pdf-fs-reducer
v1.0.2
Published
Reduce PDF file size with Ghostscript from CLI or JavaScript API.
Downloads
316
Maintainers
Readme
pdf-fs-reducer
Reduce PDF file size by downsampling embedded images through Ghostscript.
Prerequisites
Ghostscript must be installed and available in your system PATH.
| Platform | Install command / link |
| --- | --- |
| macOS | brew install ghostscript |
| Ubuntu / Debian | sudo apt install ghostscript |
| Windows | https://www.ghostscript.com/download/gsdnld.html |
Usage
npx pdf-fs-reducer <input.pdf> [options]Examples
# default mode (ebook preset)
npx pdf-fs-reducer report.pdf
# custom output file path
npx pdf-fs-reducer report.pdf -o report.reduced.pdf
# smallest output for screen viewing
npx pdf-fs-reducer report.pdf --preset screen
# force custom image DPI (overrides preset)
npx pdf-fs-reducer report.pdf --dpi 120
# reduce quality by 30% from base DPI
npx pdf-fs-reducer report.pdf --size 30
# high quality print-oriented output
npx pdf-fs-reducer report.pdf -p printer -o report.print.pdfOptions
| Flag | Description | Default |
| --- | --- | --- |
| <input> | Input PDF path (required positional argument) | n/a |
| -o, --output <path> | Output PDF path | <input-basename>.reduced.pdf in same directory |
| -p, --preset <name> | Quality preset (screen, ebook, printer, prepress) | ebook |
| -d, --dpi <number> | Custom DPI, overrides --preset | n/a |
| -s, --size <percent> | Reduce quality by percentage (example: 30 means 30% lower quality) | n/a |
| -c, --compatibility <ver> | PDF compatibility level | 1.4 |
| -V, --version | Show version | n/a |
| -h, --help | Show help | n/a |
Presets
| Preset | DPI | Best use |
| --- | --- | --- |
| screen | 72 | smallest size, on-screen viewing |
| ebook | 150 | balanced quality and file size |
| printer | 300 | high-quality printing |
| prepress | 300+ | maximum quality for publishing |
Programmatic API
Install:
npm install pdf-fs-reducerUse in Node.js:
const { PdfFilesizeReducer } = require("pdf-fs-reducer");
async function run() {
const result = await PdfFilesizeReducer.reduce({
input: "./input.pdf",
output: "./output.pdf",
preset: "ebook",
size: 30,
compatibility: "1.4"
});
console.log(result);
}
run().catch(console.error);Return value:
{
inputPath: "absolute-input-path",
outputPath: "absolute-output-path",
inputSize: 123456,
outputSize: 98765,
saved: 24691,
percent: 19.99,
effectiveDpi: 105,
qualityReduction: 30
}Sample output
pdf-fs-reducer
------------------------------------------------------------
Input : C:\docs\report.pdf (8.91 MB)
Output: C:\docs\report.reduced.pdf
Mode : eBook (150 DPI) - balanced quality and size
Engine: gswin64c
------------------------------------------------------------
- Processing PDF (3s)
Completed.
Original: 8.91 MB
Reduced : 3.72 MB
Saved : 5.19 MB (58.2% reduction)
Saved to: C:\docs\report.reduced.pdfHow It Works
pdf-fs-reducer calls Ghostscript (pdfwrite) to rebuild the PDF with lower image resolution.
In custom DPI mode, images are downsampled with bicubic interpolation.
With --size, the tool converts quality reduction percentage into an effective DPI (baseDPI * (1 - size/100)).
Text and vector drawing instructions are preserved, so reductions mainly come from image-heavy pages.
License
MIT
