Search code examples
typescriptpdfkitswissqrbill

How can I right align text in a table using SwissQRBill?


I am drawing PDF content using SwissQRBill which is an extension of PDFKit. I use TypeScript. SwissQRBill gives the option to create tables. However, I can't figure out how to right-align the text in a specific column. I would like to right-align all values in the column "Price". This is the first row in my table.

{
  fillColor: '#ECF0F1',
  columns: [
    {
      text: 'Article',
      width: mm2pt(15),
    },
    {
      text: 'Price',
    },
  ],
};

I searched the web, read the documentation of SwissQRBill and PDFKit and asked ChatGPT but I can't find the answer to my question.

This is the package I am using: https://www.npmjs.com/package/swissqrbill

This is the documentation of SwissQRBill: https://github.com/schoero/SwissQRBill/blob/master/doc/api.md#addtabletable

How can I right-align the text in specific columns in my table using SwissQRBill?


Solution

  • I had the same problem. the solution can be found in the documentation:

    https://github.com/schoero/SwissQRBill/blob/master/doc/api.md#addtabletable

    and

    https://pdfkit.org/docs/text.html#text_styling

    {
      fillColor: '#ECF0F1',
      columns: [
        {
          text: 'Article',
          width: mm2pt(15),
        },
        {
          text: 'Price',
          textOptions: {align: 'right'},
        },
      ],
    };