Using a DLEX File to Create a PDF

DLEX files are used by DynamicPDF ReportWriter to create PDFs by laying out a document based on data.

  1. First, you will instantiate a DocumentLayout using the desired DLEX file.
  2. Next you'll specify the data to be used during the layout of your document.
  3. Then you'll layout your document and save the PDF.
// Create the document's layout from a DLEX template
DocumentLayout layout = new DocumentLayout("SimpleReport.dlex");

// Specify the data to be used
NameValueLayoutData layoutData = new NameValueLayoutData();
layoutData.Add("PreparedFor", "Alex Smith");
layoutData.Add("Products", listOfProducts);

// Layout the document and save the PDF
Document document = layout.Layout(layoutData);
document.Draw(outputFilePath);
' Create the document's layout from a DLEX template
Dim MyLayout As DocumentLayout = New DocumentLayout("SimpleReport.dlex")

' Specify the data to be used
Dim MyLayoutData As NameValueLayoutData = New NameValueLayoutData()
MyLayoutData.Add("PreparedFor", "Alex Smith")
MyLayoutData.Add("Products", MyListOfProducts)

' Layout the document And save the PDF
Dim MyDocument As Document = MyLayout.Layout(MyLayoutData)
MyDocument.Draw(outputFilePath)

Specifying Layout Data

There are two types of layout data that can be used by a DocumentLayout. The first is an object value that will appear consistently on fixed pages or reports. The PreparedFor value in the above example is an example of this. This type of data can be accessed from anywhere in the layout document by specifying it in the dataName property of a record box or by putting it within pound signs in a record area (e.g. "This was prepared for #PreparedFor#.").

The other type of data, is enumerable data or a list of data that will be used by a report in the layout document. This can be an enumerable list or array of objects or data from a database. The data used by a report will be specified with its DataName property ("Products" in the example above). Layout Elements that are in the report's detail section will then access the current object or record with a DataName that matches the property or field name for that record. Layout Elements that are in a reports header or footer, will display the data for the first object or record. If a Layout Element specifies data that is not on the object, a value buy that name will try retrieved recursively from its parents (if it is on a sub report) or from a constant data value from the layout data. For example, if a RecordBox in the details of a report has its DataName property set to "PreparedFor", the value will first try to be retrieved from the report's data and if it is not found there, will be retrieved from the layout data.

Laying Out and Outputting the Document

The Layout Data is then used to layout the document by calling the layout documents Layout method and passing in the layout data. This returns a document object which is the same document object used by DynamicPDF Core Suite. Additional content or pages can be added to it, or it can simply be output to a PDF file, stream or byte array.

The Layout method also contains an overloaded method that accepts an existing document object. This is useful when you need to append a document layout to a document you are already working with, or want to append multiple document layouts to a single PDF. Keep in mind that when you use this method, the Metadata (author, keywords, subject and title) from the DLEX will be ignored.

// Layout first document (metadata will be set to the document from the DLEX)
Document document = documentLayout1.Layout(layoutData1);
// Code for 2nd DocumentLayout
// Append to Document (metadata will be ignored from the DLEX)
documentLayout2.Layout(layoutData2, document);
// Code for 3rd DocumentLayout
// Append to Document (metadata will be ignored from the DLEX)
documentLayout3.Layout(layoutData3, document);
// Save the PDF
document.Draw(outputFilePath);
' Layout first document (metadata will be set to the document from the DLEX)
Dim MyDocument As Document = MyDocumentLayout1.Layout(MyLayoutData1)
' Code for 2nd DocumentLayout
' Append to Document (metadata will be ignored from the DLEX)
MyDocumentLayout2.Layout(MyLayoutData2, MyDocument)
' Code for 3rd DocumentLayout
' Append to Document (metadata will be ignored from the DLEX)
MyDocumentLayout3.Layout(MyLayoutData3, MyDocument)
' Save the PDF
MyDocument.Draw(outputFilePath)

In this topic