Export report to PDF
Products: FastReport Cloud, FastReport Corporate Server, FastReport Publisher
This article covers the process of exporting a report using the Service solutions report processor.
Getting started
You will need the following tools and facilities:
Know how to use API key in Service solutions. How to retrieve and use API key you can learn in the Authentication and authorization article.
This article will skip over additional information on authentication and authorization.
Curl tool.
Any other REST client will work, but the examples will be built for curl.
Report template.
To learn how to upload a report template, refer to the Upload a new template article.
Active subscription to one of the following products: FastReport Cloud, FastReport Corporate Server, or FastReport Publisher.
Internet access.
Annotation
Note, that you can export the report directly from the template without saving the report. To do this, run the same commands for the report template, replacing Report in the query strings with Template, and use the template ID rather than the report ID.
Instruction
You will need the report ID to export to PDF. Execute the
GETrequest to{host_name}/api/rp/v1/Report/Rootto retrieve the root directory.Example request:
curl -X GET "{host_name}/api/rp/v1/Reports/Root" -H "accept: text/plain"Example answer:
{ "name": "RootFolder", "parentId": null, "tags": null, "icon": null, "type": "Folder", "size": 16384, "subscriptionId": "5fa919fa292a8300019349bc", "status": "None", "id": "5fa919f9292a8300019349ba", "createdTime": "2020-11-09T10:29:13.993Z", "creatorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491", "editedTime": "0001-01-01T00:00:00Z", "editorUserId": null }Directory ID from the example above:
5fa919f9292a8300019349ba.Retrieve a list of the files in the directory by executing
GETrequest to{host_name}/api/rp/v1/Reports/Folder/{id}/ListFiles?skip=0&take=10, where the directory ID should be used instead of{id}.Example request:
curl -X GET "{host_name}/api/rp/v1/Reports/Folder/5fa919f9292a8300019349ba/ListFiles?skip=0&take=10" -H "accept: text/plain"Example answer:
[ { "templateId": "5fc9ece6b792c90001d94b13", "reportInfo": null, "name": "awesome_report.fpx", "parentId": "5fa919f9292a8300019349ba", "tags": null, "icon": null, "type": "File", "size": 16927, "subscriptionId": "5fa919fa292a8300019349bc", "status": "Success", "id": "5fe4614bcd7c55000148e4c6", "createdTime": "2020-12-24T09:37:15.716Z", "creatorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491", "editedTime": "2020-12-24T09:37:15.716Z", "editorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491" } ]Report ID from the example above:
5fe4614bcd7c55000148e4c6.To export the report, you will need a directory in which to place the export file.
Retrieve the root directory of the exports; to do this, execute
GETrequest to{host_name}/api/rp/v1/Exports/Root.Example request:
curl -X GET "{host_name}/api/rp/v1/Exports/Root" -H "accept: text/plain"Example answer:
{ "name": "RootFolder", "parentId": null, "tags": null, "icon": null, "type": "Folder", "size": 16384, "subscriptionId": "5fa919fa292a8300019349bc", "status": "None", "id": "5fa919fa292a8300019349bb", "createdTime": "2020-11-09T10:29:14.002Z", "creatorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491", "editedTime": "0001-01-01T00:00:00Z", "editorUserId": null }Directory ID from the example above:
5fa919fa292a8300019349bb.To export the report, execute the
POSTrequest to{host_name}/api/rp/v1/Reports/File/{id}/Export, where report ID should be used instead of{id}.In the request body, pass JSON according to the scheme below.
{ "fileName": "awesome_result.pdf", "folderId": "5fa919fa292a8300019349bb", "locale": "en-GB", "format": "Pdf", "exportParameters": { "additionalProp1": {}, "additionalProp2": {}, "additionalProp3": {} } }folderId— ID of the directory where the export will be placed. If left blank, the export will be placed in the root folder for exports in the workspace.fileName— name of the resulting file. If you do not specify the extension, or specify it incorrectly, the server will replace it by itself.locale— localization of the exported report. This option will change the date and number formats to those corresponding to the selected ISO code (e.g., French (Switzerland) looks like “fr-CH”). If you leave this field empty or specify a non-existent country, the default locale from the subscription or English (USA) will be substituted in case the default locale is not specified.format— export format.exportParameters— export parameters. They are set similarly to the export parameters from the FastReport .NET library. A more detailed description is stored in the user documentation in the export parameters section.
If you do not specify folderId, the generated report will be saved to the root folder.
Example request:
curl -X POST "{host_name}/api/rp/v1/Reports/File/5fe4614bcd7c55000148e4c6/Export" -H "accept: text/plain" -H "Content-Type: application/json-patch+json" -d "{ \"fileName\": \"awesome_result.pdf\", \"folderId\": \"5fa919fa292a8300019349bb\", \"locale\":\"ru-RU\", \"format\": \"Pdf\"}"Example answer:
{ "format": "Pdf", "reportId": "5fe4614bcd7c55000148e4c6", "name": "awesome_result.pdf", "parentId": "5fa919fa292a8300019349bb", "tags": null, "icon": null, "type": "File", "size": 16384, "subscriptionId": "5fa919fa292a8300019349bc", "status": "InQueue", "id": "5fe46a33cd7c55000148e4c7", "createdTime": "2020-12-24T10:15:15.8039648+00:00", "creatorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491", "editedTime": "2020-12-24T10:15:15.8039697+00:00", "editorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491" }Please note the status of the
InQueuefile, it means that the task for export has been created and it has been added to the builder's queue. Already at this stage the file has received its ID for work5fe46a33cd7c55000148e4c7.You should wait a while for the export to be completed.
For information about the file, execute the
GETrequest to{host_name}/api/rp/v1/Exports/File/{id}, where the export ID should be used instead of{id}.Example request:
curl -X GET "{host_name}/api/rp/v1/Exports/File/5fe46a33cd7c55000148e4c7" -H "accept: text/plain"Example answer:
{ "format": "Pdf", "reportId": "5fe4614bcd7c55000148e4c6", "name": "awesome_result.pdf", "parentId": "5fa919fa292a8300019349bb", "tags": null, "icon": null, "type": "File", "size": 41142, "subscriptionId": "5fa919fa292a8300019349bc", "status": "Success", "id": "5fe46a33cd7c55000148e4c7", "createdTime": "2020-12-24T10:15:15.803Z", "creatorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491", "editedTime": "2020-12-24T10:15:15.803Z", "editorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491" }Note the status of the
Successfile. The report was successfully exported.To download a report, execute the
GETrequest to{host_name}/download/e/{id}, where the report ID should be passed instead of{id}.Example request:
curl -X GET "{host_name}/download/e/5fe46a33cd7c55000148e4c7" -H "accept: text/plain"The file will be received in the response.
What next?
Note! In the examples there may be no Authorization header because a cookie-based authentication model is used. For more information about authorization, read the Authentication and authorization section.