margherita pizza
margherita pizza

Reputation: 7145

pdfmake how to add more than one element in a column

I'm trying to generate pdf files using pdf make. But when I define a column I can't add more than one element to that column. I want to add a table and a separate text. But text doesn't appear in the generated pdf file.

This is my code.

columns: [
              {
                text: `Timesheet${timesheet}\n`
              },
              {
                text: `Rate${rate}\n\n`
              },
              {
                text: "Amount Due",
                table: {
                  body: xyz
                }
              }
            ]

Here table appears but the text Amount Due doesn't appear.

How do I fix this?

Upvotes: 1

Views: 6847

Answers (2)

louisvno
louisvno

Reputation: 689

You can set an array of objects inside the column (instead of an object of objects) as follows:

columns: [
              {
                text: `Timesheet${timesheet}\n`
              },
              {
                text: `Rate${rate}\n\n`
              },
              [
                {text: "Amount Due"},
                {table: {
                  body: xyz
                }}
              ]
            ]

Upvotes: 4

Arthur
Arthur

Reputation: 71

You may want to use stack, that will allow you to add multiple elements in the same column.

var dd = {
content: [
    {
        columns: [
          {
            text: `Timesheet\n`
          },
          {
            text: `Rate\n\n`
          },
          {
            stack: [
                {text: "Amount Due"},
                {table: {
                    body: [
                        ["one", "two"],
                        ["three", "four"]
                        ]
                }}
            ]
          }
        ]
    }
]

}

Upvotes: 3

Related Questions