My first report

General Description

This subsection will cover the process of creating a simple report using the report server. Before starting work, One needs to make sure that the installation of the report server was successful.

First template

To generate a report, it is necessary to create a document template in DOCX or XLSX format using MS Word/Excel, P7-Office, LibreOffice Writer/Calc, etc.

Document templates can contain tags that will be replaced with input data from the request. The tag is specified in square brackets. Example: [debt]. To learn more about creating templates in DOCX and XLSX format, see ‘Service for generating reports from a template document’.

For the first report, let’s create a simple template in DOCX format that contains a few tags: first_report_template.docx. Examples of more complex templates can be found in the examples archive.

The created template is placed on the server in the templates directory located in the service application directory.

Note

PDF page templates are stored in the templates/pdf directory located in the service application directory.

First request

The next step is to form an HTTP request.

The request for the first report in JSON format will look like this: first_report.json. The template document created earlier is specified in the id attribute of the template element. Examples of more complex requests can be found in the examples archive.

Note. XML format can also be used for requests in DOCX or XLSX format.

To get a report file, use the service of report generation from a template document.

To get the first report based on the created DOCX template, we use the URI http://localhost:8087/word_report_json.

Description

Service name

Print form generation service

Путь к сервису

[host]:[port]/print_form_pdf_json

Method

POST

Parameters

The body of the request must contain a JSON object:

                        {
    "template":
    {
        "uri": "local",
        "id": "first_report_template"
    },
    "input-data":
    {
        "ORGANIZATION": "Example JSC",
        "DATE": 01/01/2023",
        "EMP": "Peter Parker"
    },
    "options":
    {
        "formatting": {
            "tables": {
                "enable-cells-auto-merge": true
            }
        }
    }
}

A template object has attributes (fields):

  • uri - string specifying the location of the template document file depending on how the id parameter is interpreted. Supported value: local.

  • id - string which is a template identifier. It specifies the path to the template document file relative to the templates service directory. It is also used to write a report file in debug mode and to identify a request in the log.

input-data - input data to be inserted into the template.

An input-data object can contain:

  • tags of simple string data;

  • table descriptor tags;

  • list descriptor tags;

  • image tags;

  • block tags.

options - request options.

One can read more about JSON structure in the section Service for generating reports from a template document’. The service outputs the report document file in DOCX format encoded in BASE64. If it is necessary to receive the result without BASE64 encoding, the enable-binary-output flag should be set to true in the request options.

       {
   "template":
   {
       "uri": "local",
       "id": "first_report_template"
   },
   "input-data":
   {
       "ORGANIZATION": "Example JSC",
       "DATE": "01/01/2023",
       "EMP": "Peter Parker"
   },
   "options":
   {
     "enable-binary-output": true,
       "formatting": {
           "tables": {
               "enable-cells-auto-merge": true
           }
       }
   }
}

Purpose

The service is designed to generate a printed form of the document in PDF format, including footers with brief information about the document and a signature table on the last page.

Example request

curl -X POST \
'http://localhost:8087/word_report_json' \
-H 'Content-Type: application/json' \
-d '{
   "template":
   {
       "uri": "local",
       "id": "first_report_template"
   },
   "input-data":
   {
       "ORGANIZATION": "АО «Пример»",
       "DATE": "01.01.2023",
       "EMP": "Иванов Иван Иванович"
   },
   "options":
   {
       "formatting": {
           "tables": {
               "enable-cells-auto-merge": true
           }
       }
   }
}'

Example of a request to save the result to a file without base64 encoding

curl -X POST \
'http://localhost:8087/word_report_json' \
-H 'Content-Type: application/json' \
-d '{
   "template":
   {
       "uri": "local",
       "id": "first_report_template"
   },
   "input-data":
   {
       "ORGANIZATION": "Example JSC",
       "DATE": "01/01/2023",
       "EMP": "Peter Parker"
   },
   "options":
   {
       "enable-binary-output": true,
       "formatting": {
           "tables": {
               "enable-cells-auto-merge": true
           }
       }
   }
}'
-o first_report.docx

Receiving the first response

The format of the returned response

{
   error: {
       code:
       message:
   }
   result: "[base64 encoded docx/pdf file]"
}

Response example

{
   "error": null,
   "result": "UEsDBBQACAAIAPdKo...JwAAAAA="
}

Completion

As a result, we get a base64-encoded DOCX file of the first report document or an error message.