PDF is a great medium to take your data and present it to your users. By parsing your data to a PDF, you decide how it's formatted, your users can open it basically everywhere, and they can't change the content. It's like printing a document, but we're saving the planet by not wasting trees!

After reading this article, you'll know:

  • The basics for creating your own pdf templates
  • How to create a pdf property with variables
  • The different pdf actions

Basic PDF templating

Every PDF property requires a template. In this template you can define how the file should look. The template can be created beforehand within the template page, or by selecting - New - in the template selection dropdown while creating a PDF property. 

Betty Blocks uses PrinceXML to generate PDF's. This includes a mix of html (structure), css (styling) and Liquid (dynamic content).
You can look at examples and templates on the official PrinceXML website.
The setup of a PDF template is just like a regular HTML page:

<html>
  <head>
     <style>
     </style>
  </head>
  <body>
    Content
  </body>
</html>  

You can add page settings in the styling:

   @page { 
        size: A3 landscape;
      }

In the above code the size of the paper is set to A3 in landscape. You can also add content to specific areas of a page:

   @page { 
        size: A4 portrait;
        @bottom-right { content: counter(page); }
      }

In the above example a page-number is placed in the bottom right of every page.
You can still add regular CSS in the styling as well:

    @page { 
        size: A3 landscape;
        @bottom-right { content: counter(page); }
      }
      table {
        width:100%;
        border-collapse: collapse;
      }
      th {
        text-align:left;
        padding: 3px;
      }
      td {
        padding: 3px;
      }
      p {
          color: grey;
      }

You can use Liquid to dynamically load data into the table.

     Title
     
        Product
        Description
        Amount    
        Price
       
    {% for line in invoicelines %}
     
        #{{line.product.name}}
        #{{line.product.description}}        
        #{{line.amount}}        
        #{{line.price}}  
     
    {% endfor %}     

In the above example a collection of invoicelines is loaded into the table.

Creating a PDF File property

You can add PDF File properties to you model just like any other property. 

  1. Go to the Data Model by clicking on the Data Model icon in the Builder Bar.
  2. Click on a model you’d like to add the PDF property to or create a new model for the property.
  3. Within the model settings, go to the Properties subview on the right.
  4. Click on the New button to create a new property.
  5. Select PDF File as property type and name the property.
  6. Choose an existing template for the property or create a new one by selecting - New -. You can also set dynamic templates, this will use a condition to set a template.
  7. Fill in the rest of the form, more information about each setting within the form can be found in this article: Property Reference.
  8. You can add additional variables to the property, these variables can be used within the PDF template, as explained above.

When you're done with creating the property click on Save to save it.

The property has the following settings:

Template
Select a pdf template which will be used to generate the pdf. You can also pick new which will create a new empty template.
Dynamic Template
This allows you to use a condition to set a template. A template is set in this field using the UUID of the template. You can find the UUID in the url when you open the template. Example condition: A == 1 ? template X : template Y.
Allow regenerate
This allows you to regenerate your pdf file after it has already been generated before. This is useful when data for the file is subject to change.
Allow remove
This allows you to delete a pdf file from a record after generation.
Filename
This allows you to set the name of the pdf file. If you set MyPDF as filename it will show MyPDF.pdf as file when you download/open it.

Variables
Most pdf templates use variables to set data. You will have to assign these variables on the property for the template to be able to use them.

Using PDF properties in actions

There are 2 action events that use PDF properties: 

  • Pdf generate 
  • Pdf merge

Pdf generate

With this event, you can generate a Pdf file in one of the Pdf file properties of the selected object.

  1. Go to Actions by clicking on the Actions icon in the Builder Bar.
  2. Choose an action or create a new one by clicking on the New button on the upper left side of the screen.
  3. Set a description and a model for the action.
  4. Click on the Save button when you're done setting up the action.
  5. Add a new action event for the action by clicking on the plus icon.
  6. A form opens. Select the Pdf Generate event in the Kind setting.
  7. An Object that contains a Pdf property should be selected, which can be done by clicking on the Click to set button. By clicking on this button the Variables browser will pop up, in this browser you can choose the object which contains the PDF file that should be generated.
  8. Choose the Pdf property from the previously chosen object. If there is only one Pdf property within the object it will automatically be selected.
  9. There are some other settings you could play around with, information about these settings can be found in this article: Action Event Reference
  10. When you're done with setting up the action event, click Save.

Pdf merge

With this event, you can merge multiple Pdf files of the same property into one single Pdf file. If the Pdf file property didn't contain a file yet, it will be generated before merging. This event is always executed as a background job.

  1. Go to Actions by clicking on the Actions icon in the Builder Bar.
  2. Choose an action or create a new one by clicking on the New button on the upper left side of the screen.
  3. Set a description and a model for the action.
  4. Click on the Save button when you're done setting up the action.
  5. Add a new action event for the action by clicking on the plus icon.
  6. A form opens. Select the Pdf Merge event in the Kind setting.
  7. Select a variable in the Collection setting by clicking on the Click to set button. The collection can be accessed through a collection variable, or by a has many relation from an object.
  8. Choose the Pdf property from the previously chosen collection. If there is only one Pdf property within the chosen object's model, it will automatically be selected.
  9. The PDF files will be bundled into 1 PDF file, and made available through the As variable.
  10. There are some other settings you could play around with, information about these settings can be found in this article: Action Event Reference
  11. When you're done with setting up the action event you can click on the Save button to save it.
Did this answer your question?