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

0.5.4 • 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.41,956latest
0.4.0-beta.162beta

Version History

VersionDownloads (Last 7 Days)Published
0.5.41,956
0.5.3904
0.5.2795
0.5.11,659
0.5.01
0.4.017
0.4.0-beta.162
0.4.0-beta.151
0.4.0-122820232
0.3.74
0.3.60
0.3.6-beta.141
0.3.6-beta.132
0.3.6-beta.121
0.3.6-beta.111
0.3.6-beta.101
0.3.6-beta.92
0.3.6-beta.81
0.3.6-beta.71
0.3.6-beta.61
0.3.6-beta.51
0.3.6-beta.41
0.3.6-beta.31
0.3.6-beta.22
0.3.6-beta.11
0.3.50
0.3.40
0.3.3-beta.11
0.3.30
0.3.2-beta.121
0.3.20
0.3.2-beta.101
0.3.2-beta.91
0.3.2-beta.81
0.3.2-beta.71
0.3.2-beta.61
0.3.2-beta.52
0.3.2-beta.41
0.3.2-beta.31
0.3.2-beta.21
0.3.2-beta.11
0.3.2-beta.01
0.3.2-beta1
0.3.10
0.3.00
0.2.20
0.2.10
0.2.00
0.1.00

Package Sidebar

Install

npm i compress-pdf

Weekly Downloads

5,373

Version

0.5.4

License

MIT

Unpacked Size

23.3 kB

Total Files

32

Last publish

Collaborators

  • vitu.soares