Creating downloadable reports

Visit http://localhost:5606/reporting to open the jsreport Studio application where you can create templates which can then be used in your scripts.

Sample data

Create a new folder named sample as follows:

Creating a new folder

Naming the new folder

You can then create a new sample data resource inside the folder and paste the following JSON in it:

  "companyName": "Google",
  "raisedAmount": 25100000

Creating a new sample data resource

Sample data

Creating a template suitable for producing PDF reports.

  1. Right click on your folder and select New entityTemplate.

    Creating a new template

  2. Select handlebars as the templating engine and chrome-pdf as the recipe.

    Setting basic template options

  3. Select the sample data entity created before, click first on the yellow OK button and then on the blue OK button.

    Selecting template sample data

  4. Write the contents of your template in HTML. You can display the values of fields defined in JSON using the handlebars syntax {{ fieldname }}, for example:

     {{asset "./style.css"}}
     <p>Total raised amount: {{raisedAmount}} $</p>
  5. Save the template.

  6. Create a new stylesheet for your template, setting the name to style.css:

    Creating a new asset

    Creating a new stylesheet

  7. Click OK.

  8. Paste the following sample style.

    h1 {
        color: green;
  9. Save the asset.

  10. Click on your template in the sidebar and then click on Run to preview the output.

    Creating a new asset

Next steps

To generate a PDF from your template using data from an entity table, you will need to modify your script to invoke jsreport templates.