0

Create PDF

  • updated 3 yrs ago

Description

You can create your applications so they produce a PDF document that users can download or print. To generate a PDF you use form includes, the LogicNets part called Create Pdf From Form Includes-1-3, and Prince PDF, which is a licensed tool that must be included with your LogicNets subscription. In LogicNets, form includes allow you to create content under a particular data object name and you can use form includes as you model your LogicNets applications to generate PDF documents containing any content you wish.

Using the form includes a Designer user can build up an HTML structure by manually inserting HTML elements, adding LogicNets controls, loading resources, and including Knowledge Center articles. The PDF converter uses this HTML as a basis for generating the PDF. You also apply additional CSS and configuration options that include setting a front cover, applying page numbers, and including a table of contents.

The Create Pdf From Form Includes-1-3 part can either create the raw, binary data of a PDF, can create a BASE64-encoded version of the binary data, or can present to the user a download option to delay the generation of the actual PDF until the user clicks the link. Please note that raw binary data in a session file can potentially break the session file.

Adding the Part

Currently, the Designer does not have a direct option for adding the Create Pdf From Form Includes-1-3 part, and you must work in the code tab. To add this part, do the following: 
 

  1. Add any part to your logicnet.
  2. Open the added part and go to the Code tab of the part editor.
  3. Change the part name to _name = "create_pdf_from_form_includes-1-3",
  4. Remove all parameters that might have been set by the initially selected part.
  5. Go back to the Elements tab and double-click the Create Pdf From Form Includes-1-3 element to configure the part.

Editor Fields

Tab

Field Name

Description/Use

Type/Options 

Optional/Mandatory 

Basic

Mode

This is the mode in which the control should run. When using Present, the intention is to use the part in a form(part) to display the result. When choosing Process, it is intended to be used in a process node (generate the content of the PDF instead of printing a link to download). Text Mandatory

Basic

Cover location The name of the data object that specifies the Form Include that contains the layout of the cover page. Data Object

Optional

Basic

Text location The name of the data object that will contain the Form Include that contains the document content. Data Object

Mandatory

Basic

Include toc Check this to allow automatically generate a table of content based on the h1-h6 heading tags. Checkbox

Optional

Basic

Pdf file name Here the name of the PDF file can be specified. The file name is used when the PDF is downloaded. This is active when no [Output path] is chosen. Text Optional

Basic

Link text The text to be displayed when the PDF download option is used (e.g. no [Output path] is chosen). If not filled in, it falls down to [Download PDF]. Text Optional

Basic

Include PDF icon If checked, a PDF icon is added before the PDF link. The default is Off. Checkbox Optional

Basic

Output path

The name of the data object to store the generated PDF into.

NOTE: The output is set to binary data by default, this potentially breaks the session file, e.g. ensure that this data object is cleared before the session is saved (at the end of the LogicNets processing/call).

Text Optional

Basic

Output as base64 When this is checked, then the generated PDF data is automatically BASE64 encoded, which makes the content safe to be stored in the session file and makes it more easy to transfer through web calls. Checkbox Optional

Basic

Output mode

This parameter can be set to either 'nothing'/empty or 'Display Link' or 'Generate PDF'.

When leaving empty, then it falls back to determine what to do based on the configured Output path (if the output path is specified and output mode is empty, then the PDF is generated into the specified output path, if both output mode and output path are empty, then the PDF link/button is printed).

When specifying 'Display Link' the PDF link/button is always printed. When this is done recursively / repeated on the same form, it is advised to specify the output path to make the PDF link/button unique.

If 'Generate PDF' is configured, then the PDF is always saved into the specified data object.

Choice Optional

Style

Link CSS class The class name(s) that allow custom styling of the generated link (when no [Output path] is configured). Text Optional

Style

CSS includes The list of CSS files that need to be included in the HTML source before converting it to PDF. Collection Optional

Test Options

Show HTML link If checked, running in TEST will create both a PDF link and a link to the HTML file. See the Styling PDF section below for more information. Checkbox Optional

Test Options

HTML link text Customize the HTML link text shown during TEST runs. Text Optional

Test Options

Show Upload and Convert If checked, running in TEST will display options to upload an HTML file and convert to PDF using the latest CSS definitions associated with the application. See the Styling PDF section below for more information. Checkbox Optional

Common Pitfalls

  • Binary data - the binary data of the PDF can break the session structure. Ensure that the data object that contains the binary data is deleted/cleared before the end of the call.
  • Large data - the PDF van become large and if that data is saved into the session, each call to LogicNets will become slower. Ensure that the data is cleared as fast as possible in the logic.
  • Slow processing - the PDF generation can easily take several seconds. Ensure that the generation is only done on request, not on every step through the logic.
  • CSS / layout / partial pages - the layout of a web page can be different than how a printed page is layed out. Common problems arise when specific height attributes are specified, possibly cutting off content. Additionally, the all CSS files that are required to provide the correct layout need to be specified in the part. Furthermore, sometimes the layout is influenced because the content is wrapped in several other elements, this means that the CSS has to take care of the correct styling for both web page layout and PDF printed layout.
  • Flexbox not supported - Use of flexbox is not supported yet by Prince 11.
     

PDF Styling Tools

When running an application in TEST mode, additional support tools are available to make the PDF styling process more efficient.

 
First, with the Show HTML Link option checked in the Designer, the runtime TEST will show a link to the HTML page generated by the specific run of the logicnet application. This file can be downloaded and used within generic CSS tools to help create and modify the desired CSS settings.

Second, with Show Upload and Convert option checked in the Designer, the runtime TEST will show a File Upload facility that will receive any HTML file. Pressing the CONVERT button will apply the designated CSS files to the HTML file and output a PDF. With both the CSS file open in the Designer in one window, and the TEST run open in a second window, the Designer can easily edit the CSS, convert an example or control HTML file and verify the desired styling effects quickly, without having to restart the whole application.

Note that the above tools are only generated when running the create PDF part in TEST mode.
To hide these choices temporarily on any given screen, use F12 Developer tools,  locate the DIV called pdf-help and add display:none, or paste in .pdf_help {display:none} into the CSS file in-line. To remove the choices for all TEST runs, paste the same CSS into your custom CSS file for the application.

In general, the stylesheet(s) applied to the PDF follow the same syntax as for normal HTML CSS but there are some variations. For more details of the general possibilities of the Prince PDF converter and required syntax, see: https://www.princexml.com/

Example

Download this project for an example of generating a PDF that can be downloaded on request (with a link/button). (The content of the PDF is based on one or other of our training articles).

Reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
Like Follow
  • 3 yrs agoLast active
  • 22Views
  • 2 Following

Home