# pdf-lib-incremental-save

> Add incremental save functionality to pdf-lib.

Latest version **1.17.4** (published 2024-01-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install pdf-lib-incremental-save
pnpm add pdf-lib-incremental-save
yarn add pdf-lib-incremental-save
bun add pdf-lib-incremental-save
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; large bundle.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.17.4 |
| Published | 2024-01-29 |
| First published | 2023-05-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 18.6 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Remus DRAICA |
| Maintainers | remdra |
| Keywords | pdf-lib, pdf, document, create, modify, creation, modification, edit, editing, typescript, javascript, library, incremental |

## Links

- npm: https://www.npmjs.com/package/pdf-lib-incremental-save
- Repository: https://github.com/remdra/pdf-lib-incremental-save
- Homepage: https://github.com/remdra/pdf-lib-incremental-save#readme
- Issues: https://github.com/remdra/pdf-lib-incremental-save/issues
- npm.io page: https://npm.io/package/pdf-lib-incremental-save

## Dependencies (4)

- [pako](https://npm.io/package/pako.md) ^1.0.11
- [tslib](https://npm.io/package/tslib.md) ^1.11.1
- [@pdf-lib/upng](https://npm.io/package/@pdf-lib/upng.md) ^1.0.1
- [@pdf-lib/standard-fonts](https://npm.io/package/@pdf-lib/standard-fonts.md) ^1.0.0

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 1.17.4 (latest) — 2024-01-29
- 1.17.3 — 2023-11-05
- 1.17.2 — 2023-05-29

## README

# This is an extension of [pdf-lib](https://www.npmjs.com/package/pdf-lib) that provides invremental save of altered pdf documents. 

For the full documentation go to [pdf-lib](https://www.npmjs.com/package/pdf-lib) page. The documentation on this page is only related to the incremental feature.

## Table of Contents

- ...
- Usage Examples
  - ...
  - [Incremental Document Modification](#incremental-document-modification)
  - ...
- ...



### Incremental Document Modification

The incremental modification saving is designed to be used for pdf signing. The signature is added to an existing page, then only the 'incremental' PDF is generated and concatenated to the initial version.

_This example produces [this PDF](assets/pdfs/examples/incremental_document_modification.pdf)_ (when [this PDF](assets/pdfs/simple.pdf) is used for the `existingPdfBytes` variable).

<!-- prettier-ignore -->
```js
import { PDFDocument, StandardFonts } from 'pdf-lib';

// This should be a Uint8Array or ArrayBuffer
// This data can be obtained in a number of different ways
// If your running in a Node environment, you could use fs.readFile()
// In the browser, you could make a fetch() call and use res.arrayBuffer()
const existingPdfBytes = ...

// Load a PDFDocument from the existing PDF bytes
const pdfDoc = await PDFDocument.load(existingPdfBytes)

// Take a snapshot of the document
const snapshot = pdfDoc.takeSnapshot();

// Get the first page of the document
const pages = pdfDoc.getPages()
const firstPage = pages[0]

// Mark the page as modified
snapshot.markRefForSave(firstPage.ref)

// Draw a string of text diagonally across the first page
firstPage.drawText('Incremental saving is also awesome!', {
  x: 50,
  y: 4 * fontSize,
  size: fontSize
})

// Serialize the PDFDocument to bytes (a Uint8Array)
const pdfIncrementalBytes = await pdfDoc.saveIncremental(snapshot)
const pdfBytes = Buffer.concatenate([ existingPdfBytes, pdfIncrementalBytes ])

// For example, `pdfBytes` can be:
//   • Written to a file in Node
//   • Downloaded from the browser
//   • Rendered in an <iframe>
```

## License

[MIT](LICENSE.md)

---
_Source: https://npm.io/package/pdf-lib-incremental-save · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
