Skip to main content

Creating a PDF from DLEX (pdf Endpoint)

Use the pdf endpoint to generate a PDF report using DLEX.

This tutorial uses a DLEX file and its associated JSON data to create a report. You should be familiar with creating a report using a DLEX file and JSON data.

Required Resources#

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

SampleSample FolderResources
Create a PDFsamples/create-pdf-pdf-endpointNorthwind Logo.gif, SimpleReportWithCoverPage.dlex, SimpleReportWithCoverPage.json, instructions.json
  • From the Resource Manager, download SimpleReportWithCoverPage.json and instructions.json to your local system; here we assume /temp/dynamicpdf-api-samples/create-pdf-dlex.
  • After downloading, delete instructions.json and SimpleReportWithCoverPage.json from your cloud storage space using the Resource Manager.
Northwind Logo.gifcloud

See Sample Resources for instructions on adding sample resources.

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.


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

Create Instructions JSON#

Before we can call the pdf endpoint, we must create the instructions JSON document with the processing instructions for the PDF.

  • Create the following instructions and save to the local folder created above. Save the file as instructions.json.
{  "author": "Alex Smith",  "title": "My PDF From REST API",  "inputs": [    {      "type": "dlex",      "resourceName": "samples/creating-pdf-pdf-endpoint/SimpleReportWithCoverPage.dlex",      "layoutDataResourceName": "SimpleReportWithCoverPage.json"    }  ]}

In this instructions document we use the dlex input element as the input to create the finished PDF. We use a the DLEX and Pdf in cloud storage and SimpleReportWithCoverPage.json locally.


Typically you would create the DLEX in the Cloud and test using a test JSON dataset. Then, after the DLEX is correct, you would download the JSON data, or dynamically generate it locally on your client. Even though we take security seriously, you should not store proprietary data in DynamicPDF Cloud Storage.

Calling API Directly Using POST#

Completing a form and saving it as a new PDF requires the pdf endpoint. The pdf endpoint uses an instructions JSON document you send to the endpoint. The endpoint then processes the instructions to create the resultant PDF. When you call the pdf endpoint directly, you must create an instructions document. When you use one of the DynamicPDF client libraries, then the client library hides the complexities of creating the instructions document from you.

Let's call the endpoint directly using an instructions document.

  • Create the following cURL command and execute from the command-line.
curl -H "Authorization: Bearer" -F "Instructions=@c:/temp/dynamicpdf-api-samples/create-pdf-dlex/instructions.json" -F "Resource=@c:/temp/dynamicpdf-api-samples/create-pdf-dlex/SimpleReportWithCoverPage.json" -o simple-report-output.pdf
  • Open the generated PDF and notice the report followed by the merged PDF.

Figure 2. Generated PDF document consisting of a report and appended pages from PDF.

Make Request Using Client Library#

To simplify your 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. Each client library tab contains tutorial steps particular to the selected language.

Complete Source#

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

LanguageClassLocation (package/namespace/etc.)GitHub Project

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 instance of the Pdf class, which abstracts the pdf endpoint. This Pdf instance holds the created PDF after processing. We then loaded the DLEX's data into the LayoutData class and then the DLEX and the LayoutData instance into the Pdf instance using the AddDlex method. After preparing the Pdf instance, we called the pdf endpoint using the Process method. If successful, then the resultant PDF was saved to the local system.