Package Exports
- compress-pdf
- compress-pdf/dist/index.js
- compress-pdf/dist/index.mjs
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 (compress-pdf) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
compress-pdf
This library provides compress your PDFs using ghostscript
Installation
Download ghostscript binaries available in releases page inside this repository. Example name: gs_10.01.linux/windows.zip or run: npx compress-pdf --fetchBinaries [win32/linux] to download binaries to inside lib_folder/bin/gs
Then, extract and appoint:
npm install compress-pdfyarn add compress-pdfCode Usage
import path from 'path';
import fs from 'fs';
import { compress } from 'compress-pdf';
/**
* After this run:
* `npx compress-pdf --fetchBinaries [win32/linux]`
* This will download properly binaries to your current os.
*/
(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
--binPath [DIRECTORY] The directory of ghostscript binaries. Default is lib_folder/bin/gs
--fetchBinaries [win32/linux] Download binaries to default binaries pathYou can see examples in examples folder
License
This project is under MIT license, see LICENSE.md for details.