Skip to main content

Creating a PDF from DLEX (dlex-layout Endpoint)


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


This tutorial illustrates using a DLEX file and associated JSON data to generate a PDF using the DynamicPDF Cloud API's dlex-layout endpoint.

Required Resources#

To complete this tutorial, you must add the Create PDF (dlex-layout Endpoint) sample to your samples folder in your cloud storage space using the Resource Manager. After adding the sample resources, you should see a samples/creating-pdf-dlex-layout-endpoint folder containing the resources for this tutorial.

SampleSample FolderResources
Create PDF (dlex-layout endpoint)samples/creating-pdf-dlex-layout-endpointcreate-pdf-dlex-layout.dlex, create-pdf-dlex-layout.png, create-pdf-dlex-layout.json
  • From the Resource Manager, download create-pdf-dlex-layout.json to your local system; here we assume /temp/dynamicpdf-api-samples/creating-pdf-dlex-layout.
ResourceCloud/Local
create-pdf-dlex-layout.dlexcloud
create-pdf-dlex-layout.pngcloud
create-pdf-dlex-layout.jsonlocal
tip

See Sample Resources for instructions on adding sample resources.

If you are not familiar with the Resource Manager or Apps and API Keys, refer to the following tutorial and relevant Users Guide pages.

Obtaining API Key#

This tutorial assumes a valid API key obtained from the DynamicPDF Cloud API's Environment Manager. Refer to the following for instructions on getting an API key.

tip

If you are not familiar with the Resource Manager or Apps and API Keys, refer to the following tutorial and relevant Users Guide pages.

Test DLEX on Cloud#

Typically, when using the dlex-layout endpoint you would first create the DLEX on the cloud using test data.

info

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

Let's test in Designer that the report is correct.

  • Navigate to the Resource Manager and double-click on the create-pdf-dlex-layout.dlex file to open the DLEX in Designer.
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.

  • Run the report by clicking the Run Report (the green arrow) button.

Figure 1. Running a report in Designer displays the report in a new browser tab.

Make Request Using API#

  • Create a new POST request and add the two form fields listed in the following table. Note that the LayoutData is a file on your local system while DlexPath refers to the DLEX file in the Resource Manager.
ParameterParameter TypeValue
AuthorizationHeaderBearer: DP.V9xxxxxx--api key---xxxxx
DlexPathForm Fieldsamples/creating-pdf-dlex-layout-endpoint/create-pdf-dlex-layout.dlex
LayoutDataForm file field.C:/temp/dynamicpdf-api-samples/creatingpdf-dlex-layout/create-pdf-dlex-layout.json
  • Create the following cURL command where the PDF is sent to the endpoint as binary data.
curl -X POST "https://api.dynamicpdf.com/v1.0/dlex-layout" -H "Authorization: Bearer DP.xxxx--api-key--xxxxx" -F "DlexPath=samples/creating-pdf-dlex-layout-endpoint/create-pdf-dlex-layout.dlex" -F "LayoutData=@C:/temp/dynamicpdf-api-samples/creating-pdf-dlex-layout-endpoint/create-pdf-dlex-layout.json" -o create-pdf-dlex-layout-output.pdf
  • Execute the cURL command and the PDF should be written to your local system.
info

Note that if the create-pdf-dlex-layout.pdf file cannot be opened, then open it in a text editor to view the JSON error. This is a cURL limitation, Postman will display the error.

Figure 1. The report created from the DLEX and JSON layout data.

Calling Endpoint Using Client Library#

To simplify development, you can also use one of the DynamicPDF Cloud API client libraries. Use the client library of your choice to complete this tutorial section.

Complete Source#

You can access the complete source for this project at one of the following GitHub projects.

LanguageFile NameLocation (package/namespace/etc.)GitHub Project
JavaCreatingPdfDlexLayout.javacom.dynamicpdf.api.exampleshttps://github.com/dynamicpdf-api/java-client-examples
C#Program.csCreatingPdfDlexLayouthttps://github.com/dynamicpdf-api/dotnet-client-examples
NodejsCreatingPdfDlexLayout.jsnodejs-client-exampleshttps://github.com/dynamicpdf-api/nodejs-client-examples
PHPCreatingPdfDlexLayout.phpphp-client-exampleshttps://github.com/dynamicpdf-api/php-client-examples
tip

Click on the language tab of choice to view the tutorial steps for the particular language.


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. Next, we created a new instance of the DlexLayout class, which abstracts the dlex-layout endpoint. In the constructor we passed the path to the DLEX file on the Resource Manager and the LayoutData instance. 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.