Skip to content

About

Compress PDF files optimized for screen display, reducing file size while maintaining readability at 120 DPI resolution.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDF Optimizer

Compress PDF files optimized for screen display, reducing file size while maintaining readability at 120 DPI resolution.

Features

  • Screen Optimization: Targets 120 DPI for high-resolution displays
  • Aggressive Compression: Reduces file size significantly (typical target: < 3.95 MB)
  • Auto-Naming: Creates output with _compressed suffix (e.g., document_compressed.pdf)
  • Compression Feedback: Displays compression ratio and file size information
  • Quality Preservation: Maintains text and image legibility at screen resolution

Prerequisites

  • Ghostscript: External PDF processing engine (system requirement)

Installation

1. Install Ghostscript

Ghostscript is required but not installed via npm. Install it using Homebrew:

brew install ghostscript

Verify installation:

gs --version

2. Setup Project

cd pdf-optimize

No npm packages are required, but the folder is ready for future Node.js dependencies.

Usage

node optimize.js [OPTIONS]

Arguments

Argument Default Description
--in ./Original Input directory containing PDFs to compress
--out ./Optimized Output directory for compressed PDFs

Example Commands

Compress all PDFs with defaults:

node optimize.js

Processes all PDFs in ./Original and saves compressed versions to ./Optimized.

Custom input and output folders:

node optimize.js --in "./documents" --out "./compressed"

Processes all PDFs in ./documents and saves to ./compressed.

Output

The optimizer creates compressed PDF files in the output directory:

  • Searches recursively in input folder for all PDF files
  • Preserves directory structure in output folder
  • Adds _compressed suffix to optimized files (e.g., document_compressed.pdf)
  • File size reduced through compression and 120 DPI optimization
  • Suitable for email, web sharing, and screen display

Users place original PDFs in the Original folder, and optimized results are saved to the Optimized folder with the same directory structure preserved.

Configuration

If you need to adjust compression settings, edit the following in optimize.js:

const TARGET_DPI = 120;    // Adjust for quality/size tradeoff (higher DPI = better quality)
const MAX_MB = 3.95;       // Target maximum file size in megabytes

Lower DPI values (e.g., 72) create smaller files but lower quality. Higher DPI values (e.g., 150) create larger files but better quality.

Troubleshooting

Error: "gs command not found"

  • Ghostscript is not installed. Run: brew install ghostscript

No PDFs found

  • Ensure PDF files exist in the input folder (./Original by default)
  • Check that file extensions are .pdf (case-insensitive)

PDF not compressing much

  • PDFs with mostly images may compress less. Try adjusting TARGET_DPI in the script.
  • Very small files may not compress further.

Permission denied

  • Ensure PDF files are readable and you have write permission in the output directory.

About

Compress PDF files optimized for screen display, reducing file size while maintaining readability at 120 DPI resolution.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages