@cincel.digital/pdf-lib
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

This is an extension of pdf-lib that provides invremental save of altered pdf documents.

For the full documentation go to pdf-lib page. The documentation on this page is only related to the incremental feature.

Table of Contents

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 (when this PDF is used for the existingPdfBytes variable).

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, for first page
const snapshot = pdfDoc.takeSnapshot({ pageIndex: 0 });

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

// 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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.1.02latest

Version History

VersionDownloads (Last 7 Days)Published
0.1.02

Package Sidebar

Install

npm i @cincel.digital/pdf-lib

Weekly Downloads

2

Version

0.1.0

License

MIT

Unpacked Size

19.5 MB

Total Files

1586

Last publish

Collaborators

  • hector.ornelas
  • mautematico