@permettezmoideconstruire/pdf-filler

0.0.2 • Public • Published

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 descriptors
      • options.texts[].value String of text. Mandatory
      • options.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 0
      • options.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 0
      • options.texts[].size Font size in number (pixels). Default 13
      • options.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 constants fonts is exported to help for that.

Readme

Keywords

none

Package Sidebar

Install

npm i @permettezmoideconstruire/pdf-filler

Weekly Downloads

3

Version

0.0.2

License

MIT

Unpacked Size

80.8 kB

Total Files

8

Last publish

Collaborators

  • brolyus
  • algar
  • cyril.chapon