Skip to main content

dlex-layout


Use the dlex-layout endpoint with one of DynamicPDF's client libraries to create PDF reports from DLEX files.

The dlex-layout endpoint is for creating PDF reports from DLEX files. The endpoint consists of two form field parameters and returns a PDF document. The dlex-layout endpoint uses a DLEX file combined with JSON data to create PDF reports. It is an HTTP POST command that submits a form.

   Follow us on social media for latest news!
info

Refer to the following Users Guide page if you need more information illustrating how to call the endpoint directly as a REST call.

Run In Postman

API

The dlex-layout endpoint uses JSON layout data and a DLEX file to create a resultant PDF. Layout data can come from a file, a string, or a serializable object (Java, C#).

The dlex-layout endpoint is represented in the client library using the DlexLayout class. A DlexLayout class takes a path to the DLEX data and a LayoutDataResource instance. The DlexLayout class also has an overloaded constructor that takes a path to a resource residing on your local system; however, it requires using a DlexResource instance. The LayoutDataResource instance can take an object, a path to the layout data, or the layout data as a string.

public class DlexLayout : Endpoint
{
public DlexLayout(string cloudDlexPath, LayoutDataResource layoutData);
public DlexLayout(DlexResource dlexResource, LayoutDataResource layoutData);
public string DlexPath;
public PdfResponse Process();
public Task<PdfResponse> ProcessAsync();
}

public class LayoutDataResource : Resource
{
//
// Summary:
// Initializes a new instance of the DynamicPDF.Api.LayoutDataResource class using
// the layout data object and a resource name.
//
// Parameters:
// layoutData:
// Serializable object data to create PDF report.
//
// layoutDataResourceName:
// The name for layout data resource.
public LayoutDataResource(object layoutData, string layoutDataResourceName = null);
//
// Summary:
// Initializes a new instance of the DynamicPDF.Api.LayoutDataResource class using
// a JSON file with data and a resource name.
//
// Parameters:
// layoutData:
// The layout data JSON file path or JSON string.
//
// layoutDataResourceName:
// The name for layout data resource.
public LayoutDataResource(string layoutData, string layoutDataResourceName = null);
}
Source: DlexLayout.cs Source: LayoutDataResource.cs

Example

A complete example using JSON data from a file is available via one of the following GitHub projects depending upon the language you wish to use.

info

Do not be misled into thinking layout data must be a file. In a production setting you will usually generate layout data dynamically and then send it to the DynamicPDF client library as a string buffer or serializable object hierarchy. Refer to the relevant client library's example project on GitHub for example projects using a string buffer or serializable object hierarchy. The following table list the relevant classes on GitHub.

LanguageGitHub Users Guide ProjectClass/FileLocation/Package/Namespace
C#https://github.com/dynamicpdf-api/dotnet-client-examplesProgram.cs, Program.csDlexLayout, DlexLayoutObjectExample
Gohttps://github.com/dynamicpdf-api/go-clientdlex-layout-example.gogo-client-examples
Javahttps://github.com/dynamicpdf-api/java-client-examplesDlexLayoutExample.java, DlexLayoutExampleString.java, DlexLayoutExampleObject.javacom.dynamicpdf.api.examples
Node.jshttps://github.com/dynamicpdf-api/nodejs-client-examplesDlexLayoutExample.js, DlexLayoutStringBufferExample.jsnodejs-client-examples
PHPhttps://github.com/dynamicpdf-api/php-client-examplesDlexLayoutExample.js, DlexLayoutString.phpphp-client-examples
Pythonhttps://github.com/dynamicpdf-api/python-client-examplesDlexLayoutExample.pypython-client-examples

Obtain the resources used by the example from the DynamicPDF API File Manager.

Figure 1. The resources for the dlex-layout code examples.

In the following examples, the processing steps and syntax are consistent across languages. Each client library has the following classes.

  • The LayoutDataResource holds the JSON dataset used by the DLEX file to create the finished report.
  • The DlexLayout instance holds the DLEX file containing and the LayoutDataResource instance.
  • The DlexLayout instance calls the Process method and, if successful, returns a PdfResponse containing the completed PDF.

The following example illustrates using layout data from a JSON file. It also illustrates using a DLEX file in the cloud and a local DLEX file.

danger

If your DLEX file has embedded resources such as images, then you must include them as an additional resource.

info

Refer to the DlexLayoutObjectExample project in dotnet-client-examples on GitHub for an example using a simple serializable object.

public static void RunFromCloud(string apiKey, string basePath, string outputPath)
{
LayoutDataResource layoutData = new LayoutDataResource(basePath + "SimpleReportWithCoverPage.json");
DlexLayout dlexEndpoint = new DlexLayout("samples/dlex-layout/SimpleReportWithCoverPage.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 + "SimpleReportWithCoverPage.json");
DlexResource dlexResource = new DlexResource(basePath + "SimpleReportWithCoverPage.dlex", "SimpleReportWithCoverPage.dlex");
DlexLayout dlexEndpoint = new DlexLayout(dlexResource , layoutData);
dlexEndpoint.AddAdditionalResource(basePath + "NorthwindLogo.gif", "NorthwindLogo.gif");
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);
}
}
Source: DlexLayoutExample