Dynamic PDFs
Static PDFs may not always fulfill all user requirements, as the content length may vary. A dynamic PDF, on the other hand, can include content of an unknown length, and expand to encompass all that content.
Why Dynamic PDFs?
A dynamic document is generated at runtime based on the data structure to be printed. The dynamic document format language is an XML-based markup language.
When creating the PDF outline to be used, as a developer, you may not know whether the content will fill half a page, a full page, or 12 pages. A dynamic PDF may solve this issue.
Let's take the example of a bank statement. As you are designing the PDF to be generated, you do not know the number of transactions to be listed, therefore you cannot accurately predict the number of lines, or even pages, to be included in the final PDF.
An other use case is a bank with two branches using the same document template that requires, however, a different header depending on the branch. By using a dynamic PDF, which is generated at runtime, the bank can use a single Process to handle both documents.
Basic Process
In FNZ Studio, you can generate a dynamic PDF by using a PDF Output Business Object and referring to a PDF Output Table Business Object.
- Drag a Table component inside your PDF Output Business Object.
- Click on the 'C' icon next to the Expression field to open the Expression Editor.
- Call the
DYNAMICDOCUMENT()function and refer to the desired PDF Output Table Business Object. This is the key component in designing the dynamic content for your PDF.
The following sections illustrate how to deal with more complex use cases.
Further Use Cases
Combining Static and Dynamic Content (Printing Column Headers)
Is some cases, you may need to combine static and dynamic content.
Let's take the example of a PDF template containing static headers and footers. The rest of content, however, is likely to spread over multiple pages, and needs to be dynamic.
You can follow the procedure illustrated in the Basic Processsection to generate dynamic content. However, you also need to make sure that the PDF Output Table column headers are also repeated at the top of each subsequent page.
To do so, you need to perform the following steps:
-
Split your PDF Output Table in two: Create a new PDF Output Table BO containing the column headers (
PDF OT 1). The second PDF Output Table BO should contain the actual data (PDF OT 2). -
Check column widths: Make sure both
PDF OT 1, andPDF OT 2have the exact same column widths. For this, you may need to uncheck the Width dynamic property (Cell General tab). -
Insert
PDF OT 1and the rest of your content (PDF OT 2) in your PDF Output. -
Adjust design: Arrange all the content on the PDF Output BO by adjusting the positions of your content until the Preview feature displays the desired design. The best and quickest way is to use some test data.
-
Set column header properties: Within your PDF Output BO, set the properties of
PDF OT 1as follows to add column headers on each additional page:- Copy =On This Page And Copies of This Page
- Replication Strategy =Not Replicated
-
Set content properties: Within the PDF Output BO, set the properties for
PDF OT 2as follows:- Copy = Only on This Page
- Replication Strategy =Replicated
The column headers and data are now printed in the exact same location on the second, and subsequent pages.
Enhancing Dynamic Layout (Printing Fields in Different Locations)
Let's suppose you have followed the procedure described in Combining Static and Dynamic Content (Printing Column Headers). You have created a PDF with dynamic content that runs over several pages and column headers that are repeated on each page. However, you realise that, from the second page onwards, content should be printed in a different location compared to the first page.
You can place the content in another location on any additional pages by replacing the existing PDF Output BO with a two-page PDF Output.
To do so, follow the steps below:
-
On the first page, place the PDF Output Table containing the column headers (
PDF OT 1), and the PDF Output Table containing the data (PDF OT 2). Then:- Set Replication Strategy = Not Replicated for the first page.
- Set Replication Strategy = Not Replicated for
PDF OT 2. - Add a Name to
PDF OT 2(such as TableData)
-
To create subsequent pages:
- Copy and paste
PDF OT 1andPDF OT 2from the first page onto the second page. - Set Replication Strategy =Always Replicated for this second page.
- Set Replication Strategy = Replicated for
PDF OT 2. - Rearrange
PDF OT 1andPDF OT 2to obtain the required layout. - Add a Name to
PDF OT 2(such as TableData) - Go to the first page, and select
PDF OT 2. Set Next Field ID="TableData (page 2)".
- Copy and paste
-
Other components required on the second and subsequent pages can be left on the first page, but make sure to set property Copy =On All Pages. This avoids having to redefine and rearrange those components on additional pages.
Note: If you do not have enough data for a second page, add a Visibility expression on the second page to avoid rendering unnecessary pages.