PDF Creator tips

By: RalphC (WEM)

2018-04-03 13:44
last edited: 2018-04-04 10:33

Moderator

WEM has processes (process nodes) to create PDF or Word documents from a WEM Template. Access to these process nodes might not be available to you, but if they are, some info and tips might be useful...

To create PDF or Word documents we use a Document Generator Engine that generates these documents based on whatever it is you created in the WEM User Interaction Editor. What you create in the editor, is being translated by WEM into HTML so it can be displayed in your browser. The Document Generator Engine uses this generated HTML as input to translate that into either PDF or Word.

To get the best results it helps a lot if you get a “feel” for the quirks that you might run into, and how to address them.
BTW, the PDF-engine is slightly richer than the Word engine.

The WEM Master Template works with rather complex css for responsiveness and Bootstrap (remember: all WEM applications are based on Bootstrap). Which is great for browsers, but can be challenging for Documents, which do not support Bootstrap and responsiveness quite as well (as there is no need to).

For a specific project that requires it (and has a lot of document creation), we can create a specific PDF-MasterTemplate-CSS file to have a more optimized starting point, but this is not by default available.

So by default, the Document Generator uses the standard CSS definitions that are primarily used for the browser.

Especially when you use Bootstrap-elements (like columns, panels, alerts, table in bootstrap display mode) for Document output, you will run into issues.

For PDF and Word output, it is best to avoid Bootstrap elements. The Word Engine does not support most of those elements (no background colors, no rounded edges, no shading etc); PDF suffers mostly from the sizes, paddings and margins. It is best to use simple container elements (table with default display mode, not bootstrap; basic blocks, custom html in script blocks). 

However, you CAN use the bootstrap elements, but then you'll need to tweak them.

  1. Avoid running off page: use a standard html container (a div or a simple-not-bootstrap table ) with a width of "98%", this will help quite a lot!
  2. Use custom style definitions for the elements. You will need to work with css elements and classes and override some of the standard settings of existing elements. 

Most of the used html-elements have specific styling, based on bootstrap using variable settings and complex structures. 
To change font sizes or paddings or margins, you really need to know which html-element you want to tweak, and override the standard css-settings of that element with local custom css definitions.

TIP:
Using Chrome and the functionality to inspect element (right-click on a specific element) or view page source, will help you find out what the elements and their class-definitions are and how they are nested and structured, so you can use that information to tweak the settings with your custom bit of css. 
This is not possible on a generated document directly, so you need to have a normal User Interaction node in WEM with the same template contents as the pdf processnode. 


I usually make template fragments, so I can create them once and then put them on the normal interaction node as well as in the PDF process node. I use the interaction node to investigate the html structure and tweak the elements. When I'm satisfied about the result in the PDF, I disconnect the interaction node (unless it has its use within the flow anyway).
 

Summarizing:

  • You really need to try and understand the resulting html for your specific pdf, find out where it needs tweaking and then do the tweaking with inline css and html.
  • Avoid using bootstrap elements, but if you do, place them within another container that has a width of 98% to avoid running off page. Or tweak them specifically.
  • Define your own main container
    <div class="pdfcontainer">
    here goes the rest of the document contents
    </div>
    you can define a style element on top
    <style>div.pdfcontainer table {width: 98%;}</style>
    and define the custom pdf styles for all used elements as a child or descendant of this div.pdfcontainer
  • Be aware that the PDF cannot handle user interactions, so remove the Page size for paging on a datagrid or repeater and set panels to not collapsed.
  • page breaking: a useful css-snippet for avoiding page-breaking (does not alway work, depends heavily on inner content):

{
    page-break-before: avoid; 
    page-break-after: avoid; 
    page-break-inside: avoid;
}
Possible values:
auto|always|avoid|left|right|initial|inherit

Tweak on!

Ralph - WEM Xpert since 2011

"I speak to machines with the voice of humanity"
-- Marillion, Man of a thousand faces --

Sort by

Re:PDF Creator tips

By: FJP

2020-09-29 05:48
last edit: 2020-09-29 05:53

Hi, how can you exactly define the PDF Main container and then manage to get all template components being part of this container?

And what is the best way to render check-boxes that are dynamically checked or unchecked based on the data of the application and record at hand. SHould I just use input fields of multi-select or boolean for this?

Re:PDF Creator tips

By: RalphC (WEM)

2020-09-29 06:29

Moderator

You actually should not use input controls in your PDF document. WEM does not create "interactive" PDF documents. You should just display the values/fields as labels, where the result depends on the type of field: is it boolean, then yes/no, is it a multiselect based on concept set, then only those concepts selected will be displayed with their respective display names. 

Your other question is already in the original post: place a div with class pdfcontainer and read the rest. Knowledge of html structure and css is required. For the rest, I just use Chrome and inspect element on an html version of the page to inpect the resulting source and put inline css styling and custom html, usually div-containers around generated elements with a specific class so I can select that specific element and then target the contained elements with specific css.

Ralph - WEM Xpert since 2011

"I speak to machines with the voice of humanity"
-- Marillion, Man of a thousand faces --

Re:PDF Creator tips

By: Frank

2020-12-14 13:58

Has anyone tips to create a background image in the PDF that covers the whole page? Tried several options, none of them work. I tried for example:

  • image-background on the html tag
  • image background in a div with a specific ID
  • Global widget 'Set page background'

Hope anyone can help

'Failure is not an option'

Re:PDF Creator tips

By: FJP

2021-12-01 23:45

Hi there,

Some additional questions here.

1. How do you create a div container with the specific class "pdfcontainer'. When I place a div on the template I only get the option to set div-style-1 up to div-style-4.

2. Question about page-breaks regarding the following structure: Repeater > Title + Datagrid* + widget:pdf-pagebreak. 

The datagrid can be larger than page and continues on the next page. If this happens I do want to have the Title component and the header of the datagrid being repeated for following page.

How can I accomplish this?

Re:PDF Creator tips

By: RalphC (WEM)

2021-12-02 06:02

Moderator

You need to use the Script element [</>], in which you can put html, css and javacript, but you should only do that if you know html, css and javascript.

Automatically repeating title-row of repeater or datagrid is simply NOT possible. 

Ralph - WEM Xpert since 2011

"I speak to machines with the voice of humanity"
-- Marillion, Man of a thousand faces --

Re:PDF Creator tips

By: FJP

2021-12-03 06:20
last edit: 2021-12-03 07:00

Thanks Ralph, good to know. I have HTML/CSS/JS knowledge available.

But maybe I am missing something.

I added the script tag to define the PDF container. But I am not able to nest/yield components into this PDF container. I can't drag labels or templates or grids on a script component. 

Is it possible to yield add one or more template fragments in this the pdf container like:

<div class=pdfcontainer>

[template_fragment_a]

[template_fragmeent_v]

</div>

Because now I have the following HTML as output:

<main class="container">
<div class="main-content-wrapper">
<h1>PDF Test with testcontainer</h1>

<div class="pdfcontainer"></div>

<p>PDF Template fragments</p>

<p>This is a test template</p>

</div>

</main>

As an example I added screenshots of my Interaction node (having script component and template fragment) and contents of the tempalte fragment.

Furthermore: Is it possible to have custom page numbering instead of page x of n?

Thanks in advance for your reply

Re:PDF Creator tips

By: RalphC (WEM)

2021-12-03 07:31

Moderator

You can use multiple script elements, the first to open the <div> container, then normal elements in the page, and finally a closing </div> container, so all elements between these <div> and </div> script elements are contained within this specific div-container. 

With WEMScript you can add fields and functions into the script elements if needed. Some explanation on how to do that can be found in this post.

Ralph - WEM Xpert since 2011

"I speak to machines with the voice of humanity"
-- Marillion, Man of a thousand faces --

Re:PDF Creator tips

By: RalphC (WEM)

2021-12-03 07:37

Moderator

Custom paging is currently not available. The current PDF converter in WEM is limited to some basic features.

Ralph - WEM Xpert since 2011

"I speak to machines with the voice of humanity"
-- Marillion, Man of a thousand faces --

Re:PDF Creator tips

By: FJP

2021-12-03 09:11

Thanks again.

Is it possible with CSS to change font-sizing in the PDF?

Re:PDF Creator tips

By: RalphC (WEM)

2021-12-03 10:03

Moderator

Yes. I'd suggest to create a Template (fragment) for the PDF, that you first show as a normal webpage, so you can use the Browser F12-Developer Tools to investigate the generated HTML and to figure out how to do the manipulations you need using custom html and css. It is recommended to use a specific identifiable id or classname on your custom <div> element, so you can use that identifier as css-selector to manipulate css-properties and definitions for specifie elements within that container, so you may be able to override css classes and settings specifically for the situation within that specific div, for the pdf situation, without interfering with the settings outside the div.

Ralph - WEM Xpert since 2011

"I speak to machines with the voice of humanity"
-- Marillion, Man of a thousand faces --

Re:PDF Creator tips

By: JenB

2022-06-03 10:52

Hi, 

Is it any way I can override the WEM/PDF CSS? 

JenB

 

 

Re:PDF Creator tips

By: Ben

2022-06-08 17:09

Any update on we can override the WEM/PDF CSS? Thank you.

Ben

Re:PDF Creator tips

By: JenB

2022-06-09 04:43

Hello, I'm really curious if someone could provide a guide with this problem:

my.wem.io/forum?threadid=545 or if there's a way I can overide the WEM/PDF css stylesheet, since I already have my CSS template working.

Thanks for your time! 

JenB

 

 

Re:PDF Creator tips

By: RalphC (WEM)

2022-06-09 05:18

Moderator

One option is to add the PDF css to the Design Template and have it integrated, but this can only be done with a custom owned Design Template (not one of the standard available Designs) and will not get official support from WEM without additional agreements.

Another (easier) option is to internalize the styles into the Template used with the PDF Generator process. Instead of using an exterrnal css file, you can add all definitions into a <style></style> element using the Script element in the template editor.

I'd suggest you create a Template Fragment, add a Script element, place all css style definitions into this script element within a <style></style> element and make sure that the definitions are all correctly overriding existing definitions (if necessary, use the !important indicator). Then you can include this Template Fragment into all PDF nodes to become the "standard" PDF styling.

Ralph - WEM Xpert since 2011

"I speak to machines with the voice of humanity"
-- Marillion, Man of a thousand faces --

wemscore 5,621 , 544 views, 14 replies

Direct link to this thread