Tables in Templates

Tables are a very common part of most documents. They help effectively display data for easy comparison, reference, or for computing. The PDF4me document generator can effectively insert tables into documents based on the data.

Let us look at examples of how the table syntax can be created.

We can create a Product list to understand this. For that, we can create a template in the following way.

Column 1: <<foreach [product in products]>><<[product.productName]>>
Column 2: <<[product.manufactured]:"yyyy.MM.dd">>
Column 3: <<[product.price]>><</foreach>>

For the above table, let us prepare the data in the following way -

{
  "vendorName": "Instamart",
  "products": [
  {
    "productName": "Laptops",
    "price": 160000,
    "manufactured": "25/07/2022"
  },
  {
    "productName": "Keyboard",
    "price": 10000,
    "manufactured": "12/04/2022"
  },
  {
    "productName": "Speakers",
    "price": 25000,
    "manufactured": "08/05/2022"
  }
 ]
}

The output table would look like this -

Sum of value in Tables

We can also get the sum total of values in a column. For the above table, let us get the total Price of the products -

Column 1: <<foreach [product in products]>><<[product.productName]>>
Column 2: <<[product.manufactured]:"yyyy.MM.dd">>
Column 3: <<[product.price]>><</foreach>>
Column 1: $<<[products.Sum(c =>c.price)]>>

Single Columned Tables

We can look now at how to create a single-column table.

Let us design the table in the following way -

<<foreach [product in products]>>Product: <<[product.productName]>>, Manufactured On: <<[product.manufactured]:"yyyy.MM.dd">>, Product Price: $<<[product.price]>><</foreach>><</foreach -greedy>>

The output of the above table would be like -

To consider the property as a single row, the -greedy switch needs to be evoked.