Skip to main content

Use a Report- dlex-layout Endpoint


Use the dlex-layout endpoint to create PDF reports dynamically on the cloud.


After creating a DLEX report using DynamicPDF Designer, you can use the created DLEX file combined with a JSON file to generate PDF documents using an HTTP POST form request dynamically. In this tutorial, you use the dlex-layout REST endpoint to make an HTTP request for a PDF and receive an HTTP response containing the generated PDF.

Required Resources#

To complete this tutorial, if you did not add the resources in the samples folder creating-a-report-template-designer, then add them now.

  • Navigate to the Resource Manager and from the Samples dialog, add the creating-a-report-template-designer folder to add the sample resources.

Figure 1. The Create a Report (Designer Tutorial) sample project.

  • Download invoice.json to your local system,
  • Rename the downloaded file to invoice-local.json; here we assume the local folder /temp/dynamicpdf-api-samples/using-dlex-layout.
ResourceCloud/Local
invoice.dlexcloud
invoice-local.jsonlocal
invoice.jsoncloud

You should have invoice.dlex and invoice.json in your cloud storage space and invoice-local.json in your local filesystem. Now that we have our resources, let's use review the existing DLEX report.

Test DLEX on Cloud#

Typically, when using the dlex-layout endpoint you would first create the DLEX on the cloud using DynamicPDF Designer and simultaneously test your JSON dataset while developing. This is the strategy we employed when we completed the tutorial Create a Page Using a Template. However, after debugging the DLEX file, you should then use layout data that resides in your local system rather than on the cloud. We will demonstrate this difference by using invoice-local.json from your local file system rather than invoice.json. But first, let's run the report in Designer.

danger

Remember, layout data is your organization's data, keep this data safe by never storing it in the cloud - unless the data is sample data

  • In the Environment Manager, open the Resource Manager, and open the folder creating-a-report-template-designer.
  • Double-click on invoice.dlex to open the DLEX in Designer.
  • Run the report by clicking the Run Report (the green arrow) button.

Figure 2. Double-click on a DLEX file to open it in DynamicPDF Designer.

  • After closing the generated report, exit the Environment Manager.
info

Note that if the DLEX file and the JSON file have the same name and are in the same folder, then Designer will attempt to load the data automatically.

Now that we have ensured the DLEX file generates a PDF, let's use the dlex-layout endpoint to generate the PDF report.

dlex-layout Endpoint#

The dlex-layout endpoint takes a POST request containing the path to the DLEX file and the JSON data. The endpoint then generates a PDF document and is returned as an HTTP response to your calling application.

The following summarizes the HTTP POST request and the resulting response's content-type. Note that if you use one of the client libraries, then these REST call details are handled for you by the API.

Request
URLhttps://api.dynamicpdf.com/v1.0/dlex-layout
HTTP MethodPOST
Content-Typemultipart/form-data
Request Body FieldsDlexPath
Request File FieldLayoutData
Header FieldAuthorization
Response
Content-Typeapplication/pdf

Calling Endpoint#

You can call the endpoint directly or use one of DynamicPDF's client libraries. Let's illustrate calling the pdf-dlex endpoint using Postman, cURL, and then by using the Java, C#, Node.js, and PHP client libraries.

Access the complete source for this project at one of the following GitHub projects.

LanguageFile NameLocation (package/namespace/etc.)GitHub Project
JavaDesignerReportTemplate.javacom.dynamicpdf.api.exampleshttps://github.com/dynamicpdf-api/java-client-examples
C#Program.csDesignerReportTemplatehttps://github.com/dynamicpdf-api/dotnet-client-examples
NodejsDesignerReportTemplate.jsnodejs-client-exampleshttps://github.com/dynamicpdf-api/nodejs-client-examples
PHPDesignerReportTemplate.phpphp-client-exampleshttps://github.com/dynamicpdf-api/php-client-examples
tip

Select the tab of the desired language to view the tutorial steps for that particular language. Refer to Creating a PDF (dlex-layout) tutorial for detailed instructions on using one of the client libraries with the dlex-layout endpoint.


Discussion#

This tutorial illustrated how to use a DLEX file created using DynamicPDF Designer to call the dlex-layout REST endpoint. In all four languages, the steps were similar. First, we created a new LayoutData instance by loading the path to the JSON via the constructor. In the constructor, we passed the path to the DLEX file on the Resource Manager and the LayoutData instance. Next, we created a new instance of the DlexLayout class, which abstracts the dlex-layout endpoint. The DlexLayout instance saves the results as a PDF after processing if the processing was successful. Finally, we called the Process method and saved the resultant PDF.