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

1.0.4 • Public • Published

pdf-shrink

Pure JS PDF shrink tool.

It does use pdf-lib internally.

Installation

npm install pdf-shrink

Usage

With a puppeteer generated pdf

import puppeteer from 'puppeteer';
import shrinkPdf from 'pdf-shrink';

function generatePdf(html: string): Promise<Buffer> {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.setContent(html, { waitUntil: 'load' });
  const pdfDoc = await page.pdf();

  const optimizedPdf = await shrinkPdf(pdfDoc);

  return Buffer.from(savedWithoutImage);
}

What does this package really do ?

For now, it does only remove images that are duplicated in the PDF.

The example is with pupepeteer as chromium does now de-duplicate images and will generate a huge PDF file when images are duplicated.

Package Sidebar

Install

npm i pdf-shrink

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

26.2 kB

Total Files

21

Last publish

Collaborators

  • jdeniau