compress-pdf
TypeScript icon, indicating that this package has built-in type declarations

0.5.3 • Public • Published

compress-pdf

This library provides compress your PDFs using ghostscript

🚨 Breaking Change 🚨

From now on it is no longer possible to use the --fetchBinaries flag, the binaries must be obtained through the Install binaries step by step of this readme

Installation

npm install compress-pdf
yarn add compress-pdf

Install binaries

Ubuntu

sudo apt-get install ghostscript -y

MacOS

brew install ghostscript

Windows (Chocolatey)

choco install ghostscript

or download Ghostscript .exe installer

Code Usage

import path from 'path';
import fs from 'fs';
import { compress } from 'compress-pdf';

(async () => {
  const pdf = path.resolve(__dirname, 'A17_FlightPlan.pdf');
  const buffer = await compress(pdf);

  const compressedPdf = path.resolve(__dirname, 'compressed_pdf.pdf');
  await fs.promises.writeFile(compressedPdf, buffer);
})();

CLI Usage

npx compress-pdf --file [PDF_FILE] --output ./compressed.pdf

Options:
  --file [PDF_FILE] (REQUIRED)
  --output [COMPRESSED_PDF_FILE] (REQUIRED)
  --resolution [ebook/printer/screen/prepress]
  --compatibilityLevel [NUMBER] The compatibility pdf level
  --gsModule [FILE PATH] The directory of ghostscript binaries. Ex: /usr/bin/gs
  --pdfPassword The pdf password
  --removePasswordAfterCompression [BOOLEAN] Remove pdf password after compression

Usage with Docker

FROM node:18 AS build
WORKDIR /src
COPY package*.json ./
RUN npm pkg set scripts.scriptname="true" && npm i
COPY . .
RUN npm run build

FROM node:18
WORKDIR /app
RUN apt-get update \
    && apt-get install -y ghostscript
COPY package*.json ./
RUN npm pkg set scripts.scriptname="true" && npm i
COPY --from=build /src/build /app/build/
EXPOSE 8080
CMD [ "npm", "start" ]

OBS: This is just an example of how to use this lib in a docker image, note that you need to run apt-get to install ghostscript before doing anything

You can see examples in examples folder

License

This project is under MIT license, see LICENSE.md for details.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.5.3768latest
0.4.0-beta.163beta

Version History

VersionDownloads (Last 7 Days)Published
0.5.3768
0.5.2549
0.5.1868
0.5.03
0.4.016
0.4.0-beta.163
0.4.0-beta.153
0.4.0-122820233
0.3.73
0.3.62
0.3.6-beta.142
0.3.6-beta.132
0.3.6-beta.123
0.3.6-beta.113
0.3.6-beta.103
0.3.6-beta.93
0.3.6-beta.82
0.3.6-beta.72
0.3.6-beta.62
0.3.6-beta.53
0.3.6-beta.42
0.3.6-beta.33
0.3.6-beta.22
0.3.6-beta.13
0.3.53
0.3.42
0.3.3-beta.13
0.3.33
0.3.2-beta.122
0.3.23
0.3.2-beta.103
0.3.2-beta.92
0.3.2-beta.83
0.3.2-beta.72
0.3.2-beta.63
0.3.2-beta.52
0.3.2-beta.43
0.3.2-beta.32
0.3.2-beta.22
0.3.2-beta.12
0.3.2-beta.02
0.3.2-beta2
0.3.13
0.3.03
0.2.23
0.2.13
0.2.02
0.1.03

Package Sidebar

Install

npm i compress-pdf

Weekly Downloads

2,314

Version

0.5.3

License

MIT

Unpacked Size

23.2 kB

Total Files

32

Last publish

Collaborators

  • vitu.soares