JSPM

pdfpressor

1.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 104
    • Score
      100M100P100Q0F
    • License MIT

    A Node.js library to compress PDF files using rasterization and JPEG compression

    Package Exports

    • pdfpressor
    • pdfpressor/index.js

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pdfpressor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    📄 PDF Compressor

    pdfpressor is a Node.js library for compressing PDF files using rasterization and JPEG compression. It intelligently detects image-heavy PDFs and applies lossy compression using pdf-lib, sharp, and pdf-to-img.

    📦 Installation

    npm install pdfpressor

    ✨ Features

    • Detects image-heavy PDFs using a simple heuristic.
    • Rasterizes pages and compresses them as JPEGs.
    • Preserves text/vector PDFs with minimal changes.
    • Configurable DPI and JPEG quality.
    • Optional forced rasterization.

    🚀 Usage

    const { compressPdf } = require('pdfpressor');
    
    compressPdf('input.pdf', 'output.pdf', 150, 70)
      .then(stats => {
        console.log('Compression stats:', stats);
      })
      .catch(err => {
        console.error('Compression failed:', err);
      });

    Parameters

    • input (string) – Path to the source PDF file.
    • output (string) – Path to the output compressed PDF.
    • dpi (number, optional) – DPI for rasterization (default: 150).
    • quality (number, optional) – JPEG quality (default: 70).
    • force (boolean, optional) – Force rasterization even if not image-heavy.

    📊 Example Output

    📄 Input has 10 pages (5,200 KB)
    🖼 Rasterizing with JPEG compression
    → Processing page 1/10
    ...
    ✅ Compressed -> output.pdf
    Original: 5,200,000 bytes | Compressed: 1,800,000 bytes | Reduction: 65.4%