@permettezmoideconstruire/pdf-filler
v0.0.2
Published
This package is a simple [pdf-lib](https://github.com/Hopding/pdf-lib) abstraction, for Node.js
Downloads
2
Keywords
Readme
pdf-filler
This package is a simple pdf-lib abstraction, for Node.js
Installation
yarn add @permettezmoideconstruire/pdf-filler
# or
npm install --save @permettezmoideconstruire/pdf-filler
Usage
// Import it
const {
fillPdf,
fonts,
CENTER
} = require('@permettezmoideconstruire/pdf-filler')
const fs = require('fs').promises
const inputFileBytes = await fs.readFile('./input.pdf')
const outPutFileBytes = await fillPdf(inputFileBytes, {
texts: [
{
// Text in string
value: 'foo Bar !',
// Number (px) or CENTER
x: CENTER,
// Number (px) or CENTER
y: 200,
// Number (px)
size: 13,
// [R, G, B]
color: [0xFF, 0, 0XFF],
// Page index (0 based)
page: 0
}
],
font: fonts.HelveticaBold
})
await fs.writeFile(outPutFileBytes, './output.pdf')
API
async fillPdf(inputFile, options)
- inputFile Uint8Array or ArrayBuffer (straightly passed to pdf-lib.PDFDocument.load)
- options
options.texts
An array of fillers descriptorsoptions.texts[].value
String of text. Mandatoryoptions.texts[].x
Horizontal position of text. Must be a number (pixels), or the constant CENTER. When using number, text is left-aligned; when using center, text is centered. Default 0options.texts[].y
Vertical position of text. Must be a number (pixels), or the constant CENTER. When using number, text is bottom-aligned; when using center, text is centered. Default 0options.texts[].size
Font size in number (pixels). Default 13options.texts[].page
Page index where the text should appear, 0-based. Default 0
options.font
Font to use for texts. Must be a standard font, a string containing its name. A constantsfonts
is exported to help for that.