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 API's dlex-layout endpoint. The tutorial first assumes the DLEX file is on the user's local filesystem. It then assumes the DLEX file is in the user's DynamicPDF API cloud storage space.
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 File Manager. After adding the sample resources, you should see a samples/creating-pdf-dlex-layout-endpoint folder containing the resources for this tutorial.
| Sample | Sample Folder | Resources |
|---|---|---|
| Create PDF (dlex-layout endpoint) | samples/creating-pdf-dlex-layout-endpoint | create-pdf-dlex-layout.dlex, create-pdf-dlex-layout.png, create-pdf-dlex-layout.json |
- From the File Manager, download
create-pdf-dlex-layout.jsonto your local system; here we assume/temp/dynamicpdf-api-samples/creating-pdf-dlex-layout.
See Sample Resources for instructions on adding sample resources.
If you are not familiar with the File 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 API's Portal. Refer to the following for instructions on getting an API key.
If you are not familiar with the File Manager or Apps and API Keys, refer to the following tutorial and relevant Users Guide pages.
Test DLEX in Designer
Typically, when using the dlex-layout endpoint you would first create the DLEX in Designer and test using JSON data in Designer with the DLEX as you edited.
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 File Manager and double-click on the
create-pdf-dlex-layout.dlexfile to open the DLEX in Designer.
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 cURL
Let's start by using cURL to call the endpoint directly. First, we call it assuming the DLEX file is in your local filesystem. We then assume the DLEX file is in DynamicPDF API cloud storage.
The video tutorial uses Postman rather than cURL to call the endpoint.
DLEX Local
In this first example, the DLEX file resides on your local filesystem.
- Create a new
POSTrequest and add the two form fields listed in the following table. Note that theLayoutDataand the dlex are files on your local system.
| Parameter | Parameter Type | Value |
|---|---|---|
Authorization | Header | Bearer: DP.xxx-api-key-xxx |
Resource | Form file field | C:/temp/dynamicpdf-api-samples/creating-pdf-dlex-layout/creating-pdf-dlex-layout.dlex |
LayoutData | Form file field. | C:/temp/dynamicpdf-api-samples/creating-pdf-dlex-layout/creating-pdf-dlex-layout.json |
Resource | Form file field. | c:/temp/dynamicpdf-api-samples/creating-pdf-dlex-layout/creating-pdf-dlex-layout.png |
The creating-pdf-dlex-layout.png image is embedded in the dlex file as a relative path and therefore must be included as a local resource when calling the endpoint.
<page id="Page1" pageSize="letter" pageOrientation="portrait" leftMargin="50" topMargin="50" rightMargin="50" bottomMargin="50">
<image id="Image1" x="196" y="146" width="81" height="90" path="creating-pdf-dlex-layout.png"/>
<recordBox id="RecordBox2" x="56" y="258" width="386" height="20" align="center" fontSize="18" underline="false" autoLeading="true" cleanParagraphBreaks="true" expandable="false" splittable="false" dataName="title"/>
<recordBox id="RecordBox3" x="201" y="297" width="100" height="14" align="center" underline="false" autoLeading="true" cleanParagraphBreaks="true" expandable="false" splittable="false" dataName="Author"/>
</page>
- Create the following cURL command.
- Set the DLEX and image as
Resourcefields that send a file from your local filesystem. - Set the
LayoutDataas also coming from your local filesystem.
curl -X POST "https://api.dpdf.io/v1.0/dlex-layout"
-H "Authorization: Bearer DP.xxx-api-key-xxx"
-F "Resource=@C:/temp/dynamicpdf-api-samples/creating-pdf-dlex-layout-endpoint/create-pdf-dlex-layout.dlex"
-F "Resource=@C:/temp/dynamicpdf-api-samples/creating-pdf-dlex-layout-endpoint/create-pdf-dlex-layout.png"
-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.
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.
DLEX Remote
In this second example the dlex file resides in cloud storage.
- Create a new
POSTrequest and add the two form fields listed in the following table. Note that theLayoutDatais a file on your local system whileDlexPathrefers to the DLEX file in the File Manager.
| Parameter | Parameter Type | Value |
|---|---|---|
Authorization | Header | Bearer: DP.xxx-api-key-xxx |
DlexPath | Form Field | samples/creating-pdf-dlex-layout-endpoint/create-pdf-dlex-layout.dlex |
LayoutData | Form file field. | C:/temp/dynamicpdf-api-samples/creatingpdf-dlex-layout/create-pdf-dlex-layout.json |
The creating-pdf-dlex-layout.png image is embedded in the dlex file as a relative path and must resided in the same folder in DynamicPDF API cloud storage as the dlex.
- Create the following cURL command where the PDF is sent to the endpoint as binary data.
curl -X POST "https://api.dpdf.io/v1.0/dlex-layout"
-H "Authorization: Bearer DP.xxx-api-key-xxx"
-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.
Calling Endpoint Using Client Library
You can also use one of the DynamicPDF API client libraries. Use the client library of your choice to complete this tutorial section.
For all client libraries, the important coding point to remember is how you handle the dlex by the endpoint. If obtaining the dlex from your local system, then create a DlexResource class (or the client language's equivalent). If obtaining the dlex from cloud storage, then the endpoint class has a method where the relative path is specified as a string.
Be certain to add any local resources used by the dlex if you are loading the dlex from your local system.
Complete Source
You can access the complete source for this project from one of the following GitHub projects.
| Language | File Name | Location (package/namespace/etc.) | GitHub Project |
|---|---|---|---|
| Java | CreatingPdfDlexLayout.java | com.dynamicpdf.api.examples | https://github.com/dynamicpdf-api/java-client-examples |
| C# | Program.cs | CreatingPdfDlexLayout | https://github.com/dynamicpdf-api/dotnet-client-examples |
| Nodejs | CreatingPdfDlexLayout.js | nodejs-client-examples | https://github.com/dynamicpdf-api/nodejs-client-examples |
| PHP | CreatingPdfDlexLayout.php | php-client-examples | https://github.com/dynamicpdf-api/php-client-examples |
| GO | dlex-layout-example.go | go-client-examples | https://github.com/dynamicpdf-api/go-client-examples/tree/main |
| Python | DlexLayoutExample.py | python-client-examples | https://github.com/dynamicpdf-api/python-client-examples |
Click on the language tab of choice to view the tutorial steps for the particular language.
- C# (.NET)
- Java
- Node.js
- PHP
- GO
- Python
Available on NuGet:
Install-Package DynamicPDF.API
The project is named DlexLayoutTutorial and is in the dotnet-client-examples solution. It is a simple wrapper to the DlexLayoutExample class in the DynamicPdfClientLibraryExamples project.
- It first sets the api key and the base path containing the resources for the tutorial.
- It then calls the
DlexLayoutExampleclass'sRunmethod.
using DynamicPdfClientLibraryExamples.Examples;
using DynamicPdfClientLibraryExamples.Utility;
namespace DlexLayoutTutorial
{
class Program
{
static void Main(string[] args)
{
string apiKey = "DP---api-key---";
string basePath = "../DynamicPdfClientLibraryExamples/Resources/creating-pdf-dlex-layout-endpoint/";
string outputPath = "Output";
FileUtility.CreatePath(outputPath);
DlexLayoutExample.Run(apiKey, FileUtility.GetPath(basePath), FileUtility.GetPath(outputPath));
}
}
}
- The
DynamicPdfClientLibraryExamplesclass then calls two methods,RunFromCloudandRunFromLocal.
RunFromCloud
- The
RunFromCloudmethod, when loading the dlex file, gets the file from cloud storage. - The dlex file is loaded directly via the
DlexLayoutclass constructor, where it sets the relative path to the dlex file in cloud storage and theLayoutDataResourceinstance as constructor parameters.
RunFromLocal
- The
RunFromLocalmethod, when loading the dlex file, creates a newDlexResourceinstance using the local path to the dlex file. - The method then adds the png image as an additional resource to the
DlexLayoutendpoint.
using DynamicPDF.Api;
using System;
using System.IO;
namespace DynamicPdfClientLibraryExamples.Examples
{
public class DlexLayoutExample
{
public static void Run(string apiKey, string basePath, string outputPath)
{
RunFromCloud(apiKey, basePath, outputPath);
RunFromLocal(apiKey, basePath, outputPath);
}
public static void RunFromCloud(string apiKey, string basePath, string outputPath)
{
LayoutDataResource layoutData = new LayoutDataResource(basePath + "creating-pdf-dlex-layout.json");
DlexLayout dlexEndpoint = new DlexLayout("samples/creating-pdf-dlex-layout-endpoint/creating-pdf-dlex-layout.dlex", layoutData);
dlexEndpoint.ApiKey = apiKey;
PdfResponse response = dlexEndpoint.Process();
if (response.IsSuccessful)
{
File.WriteAllBytes(outputPath + "/csharp-dlex-layout-example-output.pdf", response.Content);
}
else
{
Console.WriteLine(response.ErrorJson);
}
}
public static void RunFromLocal(string apiKey, string basePath, string outputPath)
{
LayoutDataResource layoutData = new LayoutDataResource(basePath + "creating-pdf-dlex-layout.json");
DlexResource dlexResource = new DlexResource(basePath + "creating-pdf-dlex-layout.dlex", "creating-pdf-dlex-layout.dlex");
DlexLayout dlexEndpoint = new DlexLayout(dlexResource , layoutData);
dlexEndpoint.AddAdditionalResource(basePath + "creating-pdf-dlex-layout.png", "creating-pdf-dlex-layout.png");
dlexEndpoint.ApiKey = apiKey;
PdfResponse response = dlexEndpoint.Process();
if (response.IsSuccessful)
{
File.WriteAllBytes(outputPath + "/csharp-dlex-layout-local-example-output.pdf", response.Content);
}
else
{
Console.WriteLine(response.ErrorJson);
}
}
}
}
Available on NPM:
npm i @dynamicpdf/api
- Use npm to install the DynamicPDF API module.
- Create a new class named
CreatePdfDlexLayout. - Create a static
Runmethod. - In
Runcreate calls to two new methods, one that uses the DLEX in cloud storage and one that uses the DLEX locally.
RunFromCloud
- Create a new method named
RunFromCloud. - Create a new
LayoutDatainstance and in the constructor pass the path to the layout data on your local system. - Create a new
DlexLayoutinstance and in the constructor pass the cloud path in the File Manager and theLayoutDatainstance. - Add a call to the
processmethod the returns aPdfResponseinstance. - If the call to the endpoint is successful, then save the response's PDF content to a file.
RunFromLocal
- Create a new method named
RunFromLocal. - Create a new
LayoutDatainstance and in the constructor pass the path to the layout data on your local system. - Create a new
DlexResourcepassing the path to the DLEX file on your local filesystem. - Create a new
DlexLayoutinstance and in the constructor pass theDlexLayoutResourceinstance and theLayoutDatainstance. - Add the png as an additional resource to the
DlexLayoutinstance. - Add a call to the
processmethod the returns aPdfResponseinstance. - If the call to the endpoint is successful, then save the response's PDF content to a file.
import fs from 'fs';
import {
LayoutDataResource,
DlexLayout,
DlexResource
} from "@dynamicpdf/api"
export class DlexLayoutExample {
static async Run() {
var localPath = "./resources/creating-pdf-dlex-layout/";
var apiKey = "DP.--api-key--";
var outputPath = "./output/";
await this.RunFromCloud(apiKey, localPath, outputPath);
await this.RunFromLocal(apiKey, localPath, outputPath);
}
static async RunFromCloud(apiKey, localPath, outputPath) {
var layoutData = new LayoutDataResource(localPath + "creating-pdf-dlex-layout.json");
var dlexEndpoint = new DlexLayout("samples/creating-pdf-dlex-layout-endpoint/creating-pdf-dlex-layout.dlex", layoutData);
dlexEndpoint.apiKey = apiKey;
var res = await dlexEndpoint.process();
if (res.isSuccessful) {
var outFile = outputPath + "nodejs-dlex-layout-example-output.pdf";
var outStream = fs.createWriteStream(outFile);
outStream.write(res.content);
outStream.close();
} else {
console.log(res.errorJson);
}
}
static async RunFromLocal(apiKey, localPath, outputPath) {
var layoutData = new LayoutDataResource(localPath + "creating-pdf-dlex-layout.json");
var dlexResource = new DlexResource(localPath + "creating-pdf-dlex-layout.dlex", "creating-pdf-dlex-layout.dlex");
var dlexEndpoint = new DlexLayout(dlexResource, layoutData);
dlexEndpoint.dlexAdditionalResource(localPath + "creating-pdf-dlex-layout.png", "creating-pdf-dlex-layout.png");
dlexEndpoint.apiKey = apiKey;
var res = await dlexEndpoint.process();
if (res.isSuccessful) {
var outFile = outputPath + "nodejs-dlex-layout-example-local-output.pdf";
var outStream = fs.createWriteStream(outFile);
outStream.write(res.content);
outStream.close();
} else {
console.log(res.errorJson);
}
}
}
await DlexLayoutExample.Run();
- Run the application
node CreatingPdfDlexLayout.jsand the JSON is output to the console.
Available on Maven:
https://search.maven.org/search?q=g:com.dynamicpdf.api
<dependency>
<groupId>com.dynamicpdf.api</groupId>
<artifactId>dynamicpdf-api</artifactId>
<version>1.9.0</version>
</dependency>
- Create a new Maven project and add the DynamicPDF API as a dependency, also add the Apache Commons IO library.
- Create a new class named
CreatingPdfDlexLayoutwith amainmethod.
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
</dependency>
- Create a new class named
CreatingPdfDlexLayoutwith amainmethod. - Create a new static method named
Run. - In
Runcreate calls to two new methods:RunFromCloudandRunFromLocal
RunFromCloud
- Create a new method named
RunFromCloud. - Create a new
LayoutDatainstance and in the constructor pass the path to the layout data on your local system. - Create a new
DlexLayoutinstance and in the constructor pass the cloud path in the File Manager and theLayoutDatainstance. - Add a call to the
processmethod that returns aPdfResponseinstance. - If the call to the endpoint is successful, then save the response's PDF content to a file.
- Run the application and the PDF is written to your local system.
RunFromLocal
- Create a new method named
RunFromLocal. - Create a new
LayoutDatainstance and in the constructor pass the path to the layout data on your local system. - Create a new
DlexResourceinstance and pass the DLEX from your local filesystem. - Create a new
DlexLayoutinstance and in the constructor pass theDlexResourceinstance and theLayoutDatainstance. - Add the png to the
DlexLayoutinstance as an additional resource. - Add a call to the
processmethod that returns aPdfResponseinstance. - If the call to the endpoint is successful, then save the response's PDF content to a file.
- Run the application and the PDF is written to your local system.
package com.dynamicpdf.api.examples;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import com.dynamicpdf.api.DlexLayout;
import com.dynamicpdf.api.DlexResource;
import com.dynamicpdf.api.DynamicPdfCloudApiExamples;
import com.dynamicpdf.api.LayoutDataResource;
import com.dynamicpdf.api.PdfResponse;
import com.dynamicpdf.api.util.PrettyPrintUtility;
public class DlexLayoutExample {
public static void Run(String apiKey, String basePath) {
DlexLayoutExample.RunFromCloud(apiKey, basePath);
DlexLayoutExample.RunFromLocal(apiKey, basePath);
}
public static void RunFromCloud(String apiKey, String basePath) {
LayoutDataResource layoutData = new LayoutDataResource(basePath + "creating-pdf-dlex-layout.json");
DlexLayout dlexEndpoint = new DlexLayout("samples/creating-pdf-dlex-layout-endpoint/creating-pdf-dlex-layout.dlex", layoutData);
dlexEndpoint.setApiKey(apiKey);
PdfResponse response = dlexEndpoint.process();
if (response.getIsSuccessful()==true) {
try {
FileUtils.writeByteArrayToFile(new File(DynamicPdfCloudApiExamples.OUTPUT_PATH + "/java-dlex-layout-output.pdf"),
(byte[])response.getContent());
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println(PrettyPrintUtility.prettyPrintJSON(response.getErrorJson()));
}
}
public static void RunFromLocal(String apiKey, String basePath) {
LayoutDataResource layoutData = new LayoutDataResource(basePath + "creating-pdf-dlex-layout.json");
DlexResource dlexResource = new DlexResource(basePath + "creating-pdf-dlex-layout.dlex", "creating-pdf-dlex-layout.dlex");
DlexLayout dlexEndpoint = new DlexLayout(dlexResource, layoutData);
dlexEndpoint.addAdditionalResource(basePath + "creating-pdf-dlex-layout.png", "creating-pdf-dlex-layout.png");
dlexEndpoint.setApiKey(apiKey);
PdfResponse response = dlexEndpoint.process();
if (response.getIsSuccessful()==true) {
try {
FileUtils.writeByteArrayToFile(new File(DynamicPdfCloudApiExamples.OUTPUT_PATH + "/java-dlex-layout-local-output.pdf"),
(byte[])response.getContent());
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println(PrettyPrintUtility.prettyPrintJSON(response.getErrorJson()));
}
}
public static void main(String[] args) {
DlexLayoutExample.Run(DynamicPdfCloudApiExamples.API_KEY, DynamicPdfCloudApiExamples.BASE_DIR + "/creating-pdf-dlex-layout/");
}
}
Available as a Composer package:
composer require dynamicpdf/api
-
Use composer to ensure you have the required PHP libraries.
-
Create a new class named
CreatePdfDlexLayout. -
Add a
Runmethod. -
Add calls to a method named
RunCloudand a method namedRunLocal.
RunCloud
-
Create a new method named
RunCloud. -
Create a new
LayoutDatainstance and in the constructor pass the path to the layout data on your local system. -
Create a new
DlexLayoutinstance and in the constructor pass the cloud path in the File Manager and theLayoutDatainstance. -
Add a call to the
Processmethod the returns aPdfResponseinstance. -
If the call to the endpoint is successful, then save the response's PDF content to a file.
-
Run the application
php CreatingPdfDlexLayout.phpand the JSON is output to the console.
RunLocal
-
Create a new method named
RunLocal. -
Create a new
LayoutDatainstance and in the constructor pass the path to the layout data on your local system. -
Create a new
DlexResourceinstance and in the constructor pass the path to the DLEX file on your local filesystem. -
Create a new
DlexLayoutinstance that takes the theDlexResourceinstance and theLayoutDatainstance. -
Add the png as an additional resource.
-
Add a call to the
Processmethod the returns aPdfResponseinstance. -
If the call to the endpoint is successful, then save the response's PDF content to a file.
-
Run the application
php CreatingPdfDlexLayout.phpand the JSON is output to the console.
<?php
require __DIR__ . '/vendor/autoload.php';
use DynamicPDF\Api\LayoutDataResource;
use DynamicPDF\Api\DlexLayout;
use DynamicPDF\Api\DlexResource;
include_once __DIR__ . '/DynamicPdfExamples.php';
class DlexLayoutExample
{
public static function Run(string $apikey, string $path, string $output_path){
DlexLayoutExample::RunCloud($apikey, $path, $output_path);
DlexLayoutExample::RunLocal($apikey, $path, $output_path);
}
public static function RunCloud(string $apikey, string $path, string $output_path)
{
$layoutData = new LayoutDataResource($path . "creating-pdf-dlex-layout.json");
$dlexEndpoint = new DlexLayout("samples/creating-pdf-dlex-layout-endpoint/creating-pdf-dlex-layout.dlex", $layoutData);
$dlexEndpoint->ApiKey = $apikey;
$response = $dlexEndpoint->Process();
if($response->IsSuccessful)
{
file_put_contents($output_path . "php-dlex-layout-example-output.pdf", $response->Content);
} else {
echo($response->ErrorJson);
}
}
public static function RunLocal(string $apikey, string $path, string $output_path)
{
$layoutData = new LayoutDataResource($path . "creating-pdf-dlex-layout.json");
$dlexResource = new DlexResource($path . "creating-pdf-dlex-layout.dlex", "creating-pdf-dlex-layout.dlex");
$dlexEndpoint = new DlexLayout($dlexResource, $layoutData);
$dlexEndpoint->AddAdditionalResource($path . "creating-pdf-dlex-layout.png", "creating-pdf-dlex-layout.png");
$dlexEndpoint->ApiKey = $apikey;
$response = $dlexEndpoint->Process();
if($response->IsSuccessful)
{
file_put_contents($output_path . "php-dlex-layout-local-example-output.pdf", $response->Content);
} else {
echo($response->ErrorJson);
}
}
}
DlexLayoutExample::Run(DynamicPdfExamples::$API_KEY, DynamicPdfExamples::$BASE_PATH . "/creating-pdf-dlex-layout/", DynamicPdfExamples::$OUTPUT_PATH);
Available as a GO package: https://pkg.go.dev/github.com/dynamicpdf-api/go-client
-
Ensure you have the required GO libraries.
-
Create a new file named
dlex-layout-example.go. -
Add a
mainmethod. -
In
maincreate calls to two methods,processCloudPdfandprocessLocalPdf.
processCloudPdf
-
Create a new method named
processCloudPdf. -
Add a new
LayoutDatainstance and in the constructor pass the path to the layout data on your local system. -
Create a new
DlexLayoutinstance and in the constructor pass the cloud path in the File Manager and theLayoutDatainstance. -
Add a call to the
Processmethod the returns aPdfResponseinstance. -
If the call to the endpoint is successful, then save the response's PDF content to a file.
-
Run the application
go dlex-layout-example.goand the JSON is output to the console.
processLocalPdf
-
Create a new method named
processLocalPdf. -
Add a new
LayoutDatainstance and in the constructor pass the path to the layout data on your local system. -
Create a new
DlexResourceinstance and in the constructor pass the path to the DLEX on your local filesystem. -
Create a new
DlexLayoutinstance and in the constructor pass theDlexResourceinstance and theLayoutDatainstance. -
Add the png as an additional resource.
-
Add a call to the
Processmethod the returns aPdfResponseinstance. -
If the call to the endpoint is successful, then save the response's PDF content to a file.
-
Run the application
go dlex-layout-example.goand the JSON is output to the console.
package main
import (
"fmt"
"os"
"github.com/dynamicpdf-api/go-client/endpoint"
"github.com/dynamicpdf-api/go-client/resource"
)
func main() {
baseUrl := "https://api.dynamicpdf.com/"
apiKey := "DP.dASL7G5Gz8VJgEwjUly9+ooHTbSSO7pOhGrt36dHXllYQK4E1wURRI+x"
basePath := "./resources/creating-pdf-pdf-endpoint/"
processCloudPdf(baseUrl, apiKey, basePath)
processLocalPdf(baseUrl, apiKey, basePath)
}
func processLocalPdf(baseUrl string, apiKey string, basePath string) {
pr := endpoint.NewPdf()
pr.Endpoint.BaseUrl = baseUrl
pr.Endpoint.ApiKey = apiKey
layoutDataResource := resource.NewLayoutDataResource(basePath + "SimpleReportWithCoverPage.json", "SimpleReportWithCoverPage.json")
theDlexResource := resource.NewDlexResourceWithPath(basePath + "SimpleReportWithCoverPage.dlex", "SimpleReportWithCoverPage.dlex")
pr.AddNewDlexWithDlexNLayoutResources(*theDlexResource, layoutDataResource)
additionalResource := endpoint.NewDlexWithAdditionalResource(basePath + "Northwind Logo.gif", "Northwind Logo.gif")
resp := pr.Process()
res := <-resp
if res.IsSuccessful() == false {
if res.ClientError() != nil {
fmt.Print("Failed with error: " + res.ClientError().Error())
} else {
fmt.Print("Failed with error: " + res.ErrorJson())
}
} else {
os.WriteFile(basePath+"pdf-dlex-pdf-local-output.pdf",
res.Content().Bytes(), os.ModeType)
}
}
func processCloudPdf(baseUrl string, apiKey string, basePath string) {
pr := endpoint.NewPdf()
pr.Endpoint.BaseUrl = baseUrl
pr.Endpoint.ApiKey = apiKey
layoutDataResource := resource.NewLayoutDataResource(basePath+"SimpleReportWithCoverPage.json", "SimpleReportWithCoverPage.json")
pr.AddDlexWithCloudResourceNLayoutData("samples/creating-pdf-pdf-endpoint/SimpleReportWithCoverPage.dlex", layoutDataResource)
resp := pr.Process()
res := <-resp
if res.IsSuccessful() == false {
if res.ClientError() != nil {
fmt.Print("Failed with error: " + res.ClientError().Error())
} else {
fmt.Print("Failed with error: " + res.ErrorJson())
}
} else {
os.WriteFile(basePath+"pdf-dlex-pdf-remote-output.pdf",
res.Content().Bytes(), os.ModeType)
}
}
Available at: pip install dynamicpdf-api
-
Ensure you have the required Python libraries.
-
Create a new file named
DlexLayoutExample.py. -
Add a
dlex_layoutmethod. -
Add calls to two new methods,
dlex_layout_cloudanddlex_layout_local.
dlex_layout_cloud
-
Create a new method names
dlex_layout_cloud. -
In
dlex_layout_cloudcreate a newLayoutDatainstance and in the constructor pass the path to the layout data on your local system. -
Create a new
DlexLayoutinstance and in the constructor pass the cloud path in the File Manager and theLayoutDatainstance. -
Add a call to the
processmethod the returns aPdfResponseinstance. -
If the call to the endpoint is successful, then save the response's PDF content to a file.
-
Run the application
python DlexLayoutExample.pyand the JSON is output to the console.
dlex_layout_local
-
Create a new method names
dlex_layout_local. -
In
dlex_layout_localcreate a newLayoutDatainstance and in the constructor pass the path to the layout data on your local system. -
Create a new
DlexResourceinstance and in the constructor pass the path to your local DLX file. -
Create a
DlexLayoutinstance and in the constructor pass theDlexResourceinstance and theLayoutDatainstance. -
Add the png as an additional resource.
-
Add a call to the
processmethod that returns aPdfResponseinstance. -
If the call to the endpoint is successful, then save the response's PDF content to a file.
-
Run the application
python DlexLayoutExample.pyand the JSON is output to the console.
from dynamicpdf_api.dlex_layout import DlexLayout
from dynamicpdf_api.dlex_resource import DlexResource
from dynamicpdf_api.layout_data_resource import LayoutDataResource
from Shared import *
def dlex_layout(apiKey, full_path):
dlex_layout_cloud(apiKey, full_path)
dlex_layout_local(apiKey, full_path)
def dlex_layout_cloud(apiKey, full_path):
layoutData = LayoutDataResource(full_path + "creating-pdf-dlex-layout.json")
dlexEndpoint =DlexLayout("samples/creating-pdf-dlex-layout-endpoint/creating-pdf-dlex-layout.dlex", layoutData)
dlexEndpoint.api_key=apiKey
response = dlexEndpoint.process()
if response.is_successful:
with open(output_path + "python-dlex-layout-example.pdf", "wb") as output_file:
output_file.write(response.content)
else:
print(response.error_id)
def dlex_layout_local(apiKey, full_path):
layoutData = LayoutDataResource(full_path + "creating-pdf-dlex-layout.json")
dlexResource = DlexResource(full_path + "creating-pdf-dlex-layout.dlex", "creating-pdf-dlex-layout.dlex")
dlexEndpoint =DlexLayout(dlexResource, layoutData)
dlexEndpoint.add_additional_resource(full_path + "creating-pdf-dlex-layout.png")
dlexEndpoint.api_key=apiKey
response = dlexEndpoint.process()
if response.is_successful:
with open(output_path + "python-dlex-layout-local-example.pdf", "wb") as output_file:
output_file.write(response.content)
else:
print(response.error_id)
if __name__ == "__main__":
dlex_layout(api_key, base_path + "/creating-pdf-dlex-layout/")
In all six languages, the steps were similar. First, we created a new LayoutData instance by loading the path to the JSON via the constructor.
Remote DLEX
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 File Manager and the LayoutData instance.
Local DLEX
We created a new instance of a DlexResource where we passed the path to the DLEX file on your local filesystem. We then created an instance of the DlexLayout class and in the constructor we passed theDlexResource instance and the LayoutData instance. We also added the png as an additional resource.
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.