DynaReport

DynaReport is a cloud based, interactive report engine which helps in generating well formatted PDF reports from Word / DOCX templates.

To accelerate the process of creating your reports and applications, DynaReport takes advantage of Microsoft Word's design capabilites. Simply create a Microsoft Word file and design your report.

Documentation

Template Variables

Variables can be used in the content of Word templates. Template variables are written in single curly brackets. When generating reports, values can be assigned to variables.

Suppose we have a template with content like the one below.

Hello {first_name} {last_name}. You'll pay {currency}{amount} each month once your free trial ends on {date}.

Let's assign the following values ​​to our template.

...
data: {
  "first_name": "Jane",
  "last_name": "Doe"
  "currency": "$"
  "amount": "9",
  "date": "July 18, 2019"
}
...

The output of the report will be as follows.

Hello Jane Doe. You'll pay $9 each month once your free trial ends on July 18, 2019.

Loops

Suppose we have a template with content like the one below.

{page_title}
-----------------
{#customers}
  {first_name}
  {last_name}
  {bank_account}
  * * *
{/customers}

Let's assign the following values ​​to our template.

...
"data": {
  "page_title": "Customer List Report",
  "bank_account": "No bank account specified.",
  "customers": [
    {
      "first_name": "John",
      "last_name": "Doe"
      "bank_account": "IBAN US 00 0000 0000"
    },
    {
      "first_name": "Jane",
      "last_name": "Doe"
    }
  ]
}
...

The output of the report will be as follows.

Customer List Report
-----------------
  John
  Doe
  IBAN US 00 0000 0000
  * * *
  Jane
  Doe
  No bank account specified.
  * * *

Please note that the default value for "bank_account" is specified outside of the "customers" array.

Using With REST API

Uploading Templates

Templates can be uploaded via the following REST API. [POST] https://api.apiden.com/dynareport/template
Content-Type: application/json
{
  "apiKey": "3a3e7ea82f",
  "fileName": "Invoice Template.docx",
  "fileBase64" : "..."
}

apiKey: Your API key.
fileName: A file name that identifies your file.
fileBase64: Base64 encoded output of file contents.

Expected response: [200 OK] application/json
{
  "id": "4d1ba9f7812768246a9eb678"
}

id: ID of uploaded Word template. This value will be used to generate reports later.

Generating Reports

The following REST API should be used to generate reports from a template we uploaded.

Suppose that the template we have has three variables named {first_name}, {last_name} and {desc}. [POST] https://api.apiden.com/dynareport/report
Content-Type: application/json
{
  "apiKey": "3a3e7ea82f",
  "templateId": "4d1ba9f7812768246a9eb678",
  "outputType": "pdf",
  "data": {
    "first_name": "Jane",
    "last_name": "Doe",
    "desc": "This is a description paragraph."
  }
}

apiKey: Your API key.
templateId: The ID of the template we uploaded.
outputType: The output type of the report can be "docx" or "pdf".
data : Variable names and values in the template.

Expected response: [200 OK] application/json
{
  "id": "5d1bae4ccf46da2cf4070236",
  "downloadUrl": "https://api.apiden.com/dynareport/report/invoice-template/53a9a06dad10ee9bb7458dae67d"
}

id: The ID of the generated report for purely informative purposes.
downloadURL: The download URL of the generated report.

So far, we've uploaded a template and generated a report. Now we will download the report we generated.

Downloading Reports

There is a one-time download token at the end of the download URL. For security purposes, once the report has been downloaded, it cannot be accessed again at the same URL.

Downloading the reports is very easy. API key is not required. The generated report can be downloaded with a simple GET request.

[GET] https://api.apiden.com/dynareport/report/invoice-template/53a9a06dad10ee9bb7458dae67d

Using With PHP Client

You can easily upload your templates and generate reports with API Den's Open Source PHP package.

GitHub: https://github.com/api-den/dynareport-php

Add package to your project

composer require api-den/dynareport-php

then upload a template, generate and download a report in a few lines of code.

$dynaReport = new DynaReport();

// API Key from apiden.com
$dynaReport->setApiKey("2fd3a35e2a");

// Upload a template from your computer
$dynaReport->uploadTemplate('invoice-template.docx');

// Set template variables and values
$dynaReport->setData([
  'first_name' => 'Jane',
  'last_name' => 'Doe',
  'desc' => 'Invoice example',
  'company' => 'API Den',
  'website' => 'www.apiden.com'
]);

// Finally generate, download and save you report
$dynaReport->generateAndDownloadReport(
  $dynaReport->getUploadedTemplateId(),
  'my-generated-report.pdf'
);