Skip to content

Latest commit

 

History

History
478 lines (308 loc) · 17.8 KB

index.md

File metadata and controls

478 lines (308 loc) · 17.8 KB

Index


Classes

Class: SwissQRBill

Defined in: src/pdf/swissqrbill.ts

Description

The SwissQRBill class creates the Payment Part with the QR Code. It can be attached to any PDFKit document instance using the attachTo method.

Example

const data = {
  amount: 1994.75,
  creditor: {
    account: "CH44 3199 9123 0008 8901 2",
    address: "Musterstrasse",
    buildingNumber: 7,
    city: "Musterstadt",
    country: "CH",
    name: "SwissQRBill",
    zip: 1234
  },
  currency: "CHF",
  debtor: {
    address: "Musterstrasse",
    buildingNumber: 1,
    city: "Musterstadt",
    country: "CH",
    name: "Peter Muster",
    zip: 1234
  },
  reference: "21 00000 00003 13947 14300 09017"
};

const pdf = new PDFDocument({ autoFirstPage: false });
const qrBill = new SwissQRBill(data);

const stream = createWriteStream("qr-bill.pdf");

qrBill.attachTo(pdf);
pdf.pipe(stream);
pdf.end();

Constructor: new SwissQRBill(data[, options])

Defined in: src/pdf/swissqrbill.ts

Parameters
  • data Data The data to be used for the QR Bill.
  • options PDFOptions Options to define how the QR Bill should be rendered. optional
Return Type

SwissQRBill

Throws
  • ValidationError Throws an error if the data is invalid.
Description

Creates a new SwissQRBill instance.


Property: SwissQRBill.width

public static readonly

Defined in: src/pdf/swissqrbill.ts

Type

number

Description

The horizontal size of the QR Bill.


Property: SwissQRBill.height

public static readonly

Defined in: src/pdf/swissqrbill.ts

Type

number

Description

The vertical size of the QR Bill.


Method: SwissQRBill.attachTo(doc[, x][, y])

public

Defined in: src/pdf/swissqrbill.ts

Parameters
  • doc PDFDocument The PDFKit instance
  • x number The horizontal position in points where the QR Bill will be placed. optional Default: 0
  • y number The vertical position in points where the QR Bill will be placed. optional Default: number
Return Type

void

Description

Attaches the QR-Bill to a PDFKit document instance. It will create a new page with the size of the QR-Slip if not enough space is left on the current page.


Method: SwissQRBill.isSpaceSufficient(doc, xPosition, yPosition)

public static

Defined in: src/pdf/swissqrbill.ts

Parameters
  • doc PDFDocument The PDFKit document instance
  • xPosition number The horizontal position where the QR Bill will be placed.
  • yPosition number The vertical position where the QR Bill will be placed.
Return Type

boolean true if there is enough space, otherwise false

Description

Checks whether there is enough space on the current page to add the QR Bill.


Class: SwissQRCode

Defined in: src/pdf/swissqrcode.ts


Constructor: new SwissQRCode(data[, size])

Defined in: src/pdf/swissqrcode.ts

Parameters
  • data Data The data to be encoded in the QR code.
  • size number The size of the QR code in mm. optional Default: 46
Return Type

SwissQRCode

Throws
  • ValidationError Throws an error if the data is invalid.
Description

Creates a Swiss QR Code.


Method: SwissQRCode.attachTo(doc[, x][, y])

public

Defined in: src/pdf/swissqrcode.ts

Parameters
  • doc PDFDocument The PDF document to attach the Swiss QR Code to.
  • x number The horizontal position in points where the Swiss QR Code will be placed. optional Default: number
  • y number The vertical position in points where the Swiss QR Code will be placed. optional Default: number
Return Type

void

Description

Attaches the Swiss QR Code to a PDF document.


Class: Table

Defined in: src/pdf/table.ts

Description

The Table class is used to create tables for PDFKit documents. A table can be attached to any PDFKit document instance using the attachTo method.

Example

const tableData = {
  rows: [
    {
      backgroundColor: "#ECF0F1",
      columns: [
        {
          text: "Row 1 cell 1"
        }, {
          text: "Row 1 cell 2"
        }, {
          text: "Row 1 cell 3"
        }
      ]
    }, {
      columns: [
        {
          text: "Row 2 cell 1"
        }, {
          text: "Row 2 cell 2"
        }, {
          text: "Row 2 cell 3"
        }
      ]
    }
  ]
};
const pdf = new PDFDocument();
const table = new Table(tableData);

const stream = createWriteStream("table.pdf");

table.attachTo(pdf);
pdf.pipe(stream);
pdf.end();

Constructor: new Table(data)

Defined in: src/pdf/table.ts

Parameter
  • data PDFTable The rows and columns for the table.
Return Type

Table The Table instance.

Description

Creates a new Table instance.


Method: Table.attachTo(doc[, x][, y])

public

Defined in: src/pdf/table.ts

Parameters
  • doc PDFDocument The PDFKit document instance
  • x number The horizontal position in points where the table be placed. optional Default: number
  • y number The vertical position in points where the table will be placed. optional Default: number
Return Type

void

Throws
  • Error Throws an error if no table rows are provided.
Description

Attaches the table to a PDFKit document instance beginning on the current page. It will create a new page with for every row that no longer fits on a page.


Type alias: PDFBorderColor

Defined in: src/pdf/table.ts

Type

union

Description

Can be used to set the color of the border of a table, row or column.


Type alias: PDFBorderWidth

Defined in: src/pdf/table.ts

Type

union

Description

Can be used to set the width of the border of a table, row or column.


Type alias: PDFPadding

Defined in: src/pdf/table.ts

Type

union

Description

Can be used to set the padding of a table cell.


Interface: PDFTable

Defined in: src/pdf/table.ts

  • rows Array Table rows.

  • align "center" | "left" | "right" Horizontal alignment of texts inside the table optional

  • backgroundColor string Background color of the table. optional

  • borderColor PDFBorderColor The colors of the border optional

  • borderWidth PDFBorderWidth Width of the borders of the row. optional

  • fontName string Font of the text inside the table. optional

  • fontSize number Font size of the text inside the table. optional

  • padding PDFPadding Cell padding of the table cells. optional

  • textColor string Text color of texts inside table. optional

  • textOptions TextOptions Same as text PDFKit text options. optional

  • verticalAlign "bottom" | "center" | "top" Vertical alignment of texts inside the table optional

  • width number Width of whole table. optional


Interface: PDFRow

Defined in: src/pdf/table.ts

  • columns Array Table columns.

  • align "center" | "left" | "right" Horizontal alignment of texts inside the row optional

  • backgroundColor string Background color of the row. optional

  • borderColor PDFBorderColor The colors of the border optional

  • borderWidth PDFBorderWidth Width of the borders of the row. optional

  • fontName string Font of the text inside the row. optional

  • fontSize number Font size of the text inside the row. optional

  • header boolean A header row gets inserted automatically on new pages. Only one header row is allowed. optional

  • height number Height of the row. Overrides minHeight and maxHeight optional

  • maxHeight number Maximum height of the row optional

  • minHeight number Minimum height of the row optional

  • padding PDFPadding Cell padding of the table cells inside the row. optional

  • textColor string Text color of texts inside the row. optional

  • textOptions TextOptions Same as text PDFKit text options. optional

  • verticalAlign "bottom" | "center" | "top" Vertical alignment of texts inside the row optional


Interface: PDFColumn

Defined in: src/pdf/table.ts

  • text boolean | number | string Cell text.
  • align "center" | "left" | "right" Horizontal alignment of the text inside the cell optional
  • backgroundColor string Background color of the cell. optional
  • borderColor PDFBorderColor The colors of the border optional
  • borderWidth PDFBorderWidth Width of the borders of the row. optional
  • fontName string Font of the text inside the cell. optional
  • fontSize number Font size of the text inside the cell. optional
  • padding PDFPadding Cell padding of the table cell. optional
  • textColor string Text color of texts inside the cell. optional
  • textOptions TextOptions Same as text PDFKit text options. optional
  • verticalAlign "bottom" | "center" | "top" Vertical alignment of the text inside the cell optional
  • width number Width of the cell. optional