0.1.9 • Published 5 years ago

pdf-templater v0.1.9

Weekly downloads
39
License
MIT
Repository
github
Last release
5 years ago

PDF Templater

pdf-templater does the same as docxtemplater but for PDF. It uses pdf-lib as parser/generator.

Works in any environment: Node, Browser, React Native

Example

Read how to load pdf from pdf-lib

import { PDFDocument } from 'pdf-lib'
import templatePDF from 'pdf-templater'

const doc = await PDFDocument.load(/* existing pdf array buffer */)
templatePDF(doc, {
    ['entry', 'value'],                         // Replaces all `{entry}` matches to `value`
    [/^A.*/, 'a line'],                         // Replaces all lines starting with A to `a line`
    [/^A.*/, (match) => match[0].substring(1)]  // Replacement value can be a function that receives each match
})
const outputBase64 = doc.saveAsBase64() // Save the doc already replacement
// ....

This can throw an error in multiple cases, wrap it inside a try..catch.

Recommended: validate your pdf with some pdf inspector and make sure the matches are in the same text block. Editors usually split text (even in the same line) into multiple text blocks, which will not be caught by your full regex

Tip: font glyphs must be already available in the pdf file. If it is not there, write all letters you will use as invisible (white, with the same font and the smallest size) hidden somewhere.

0.1.9

5 years ago

0.1.8

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.0

5 years ago