icon

Getting Started with CraftMyPDF’s PDF Designer

CraftMyPDF
CraftMyPDF

1. Introduction

CraftMyPDF offers a web-based drag & drop PDF template editor that lets you design templates and generate pixel-perfect PDF documents from reusable templates. The PDF template editor includes a rich set of layout and components to develop beautiful PDFs with powerful expressions, formatting, page breaks, and data-binding.

Our PDF Generation API allows you to generate PDF documents via REST API. In addition, CraftMyPDF integrates with no-code platform Zapier and Integromat for you to automate the creation of PDF documents in your workflow.

To learn about the visual components such as Text, Image, Chart, and other visual elements, head over to our Guide to Components.

In this article, we will cover the basics of PDF template editor, page breaks, data-binding, preview, and others.

1.1 The workflow for template design and PDF generation

The followings are the 4 simple steps to design PDF templates and generate PDF documents:

Step 1 – Import, manipulate, or view the JSON data available in the Data tab.

It’s important to have your JSON data ready(On the left) before designing the template. It’s because the JSON schema will be used for auto-complete drop-down and the JSON will be used for PDF preview.

The JSON data on the left is a sample, you have to substitute it with your JSON data for the actual PDF generation.

Step 2 – Modify the PDF template in the Designer tab. You may use expressions with the components to create dynamic PDF documents.

An expression is enclosed in {{ syntax }} .To use JSON data in the expressions, {{ data.[field] }}. Replace [field] with the JSON field you want to display

Step 3 – Use the Preview tab to preview PDF or debug the expressions, you may also generate PDF documents here. See the section Preview of PDF for details

Step 4 – The final step is to automate PDF generation with Zapier, Integromat, or REST API. See the Integrations section below.

2. Designer

The Designer tab is a drag-and-drop environment for designing a PDF template. There are three (3) different sections in the PDF designer:

(a) Header Section
(b) Normal Section
(c) Footer Section

Header section

The header section appears at the top of each page. This includes things such as page number, document title, and other information.

Footer section

The footer section appears on the bottom of each page, and it usually contains the page number, document title, or other information.

Normal section

The normal section is the body of the report where the report data appears. If data binding is enabled, the section will be repeated once per record; see below for data binding.

2.2 Data binding

2.2.1 All sections – The JSON data

A special variable data is to access the JSON data. You can use it with expressions.

The expressions with data variables and fields
Preview PDF(HTML) of the rendered data and the JSON data

2.2.2 Data binding for normal sections

(i) If data binding is enabled, the section will be repeated once per record. the Data/Data Source section in the property panel is mandatory and it only accepts an array. You can use an expression to bind it to an array. Additional filtering and ordering can be done for data with an expression, see the section below for filtering and ordering of the rows.
(ii) A special variable row is available for sections that data binding is enabled. To access a field in the row in an expression, use the expression row.field.

(iii) The variable rowIndex is a running index of the current row, it starts from zero.

2.2.3 Variables for header & footer

The expression {{sys.pageNumber}} or {{sys.totalPages}} displays the current page number and total pages.

2.2.4 Complex data with subsections

A subsection component is a component that contains sub-header, sub-footer and sub-normal section. It can be used to iterate the rows in an array. combined with a section, you can iterate a complex hierarchical structured JSON.

With subsection, a special variable parent let you access the parent data.

A subsection within a normal section. Double click on the subsection you will enter into the subsection mode as follows
Subsection mode, click on the back button to return to the main designer. A special variable parent allows you to access the parent data.
The PDF produced by normal section and subsection.

2.2.5 Data manipulation

2.2.5.1 Filtering array data

Expression:

{{array.filter((var)=> condition)}}

The method filter filters an array according to provided criteria, and it returns a new array containing the items that meet the criteria. Read more at Mozilla

e.g: To filter an array based on the project name Polaris

{{data.items.filter((e)=>e.project=='Polaris')}}

2.2.5.2 Sorting array data

Expression:

{{array.sort((comp1, comp2)=> condition)}}

The method sort reorders an array according to provided criteria, and it returns a new array containing the sorted items. Read more at Mozilla

e.g: To sort an array based on the project names

{{data.items.sort((a,b)=>a.project>b.project?1:-1)}}

Tips:

You can also use our built-in method sort(field,array, direction), find out more on docs: Expressions

2.3 Common issues for data-binding

2.3.1 “Undefined” in generated PDFs

The possible root cause you may encounter are:

(i) Incorrect use of syntax {{data.[field]}} to access JSON data

In most cases, the keyword data is missing. Make sure you use the correct syntax as follows:

{{data.[field]}}

Remember to replace [field] with the JSON field that you want to display

for example, if you want to display a JSON field position, use the following expression

{{ data.position }}

(ii) The field doesn’t exist in the JSON data

Make sure the field you are using is present in the JSON data.

Optionally, you can use our built-in expression isNullOrEmpty, and Javascript’s conditional (ternary) operator to check for a null or empty value, then substitute with a new text. The following is an example to check for the field company_name, if it’s empty then it will display “THIS IS EMPTY”.

{{ isNullOrEmpty(data.company_name) ? “THIS IS EMPTY”: data.company_name }}

2.3.2 Debug for data-binding

To display available JSON data, you can use the following expression:

{{ JSON.stringify(data) }}

It displays the data in JSON

2.4 Expressions

An expression is essentially a javascript syntax enclosed in {{ and }}. The expression is any valid set of variables, operators, and expressions that evaluates to a single value. The value may be a number, a string, an array or a logical value.

The following is a text component that supports expression.

Type of functions

(i) Standard JavaScript libraries – JavaScript standard built-in functions and objects such as Math, String, Array or any standard Javascript methods.

(ii) External libraries – We support Numeral.js and Moment.js out of the box

(iii) CraftMyPDF’s built-in functions – functions for formatting, number and string. You may find them in the designer Docs: Expressions

2.5 Page breaks for sections

Break inside indicates whether or not a page break should occur inside the specified element.

There are 2 types of break inside:

  • Auto – (Default) Automatic page breaks (neither forced nor forbidden)
  • Avoid – Avoid page breaks inside the element.

Break after – Force page breaks after this section if this is enabled

3. Preview of PDF

Preview tab is used to preview the PDF. It’s important to have your JSON data ready(in Data Tab), the sample JSON data will be used for PDF preview.

There are 2 modes of PDF preview:

Generate PDF

  • Use this to generate the actual PDF. It typically takes a few seconds.
  • This renders a full PDF and accurately the same PDF that you generate with REST API.
  • Generating PDFs with web console costs 0.5 credit.

Preview PDF(in HTML) – Default mode

  • Previewing in HTML is auto and fast.
  • However, this renders everything in one page without page breaks.
  • Use this for debugging expressions or preview the data/layout.

4. Data Tab

Manipulate your JSON data in the Data tab. It’s important to have your JSON data ready(On the left) because the JSON schema will be used for auto-complete drop-down and the JSON will be used for PDF preview. The JSON data on the left is a sample, you have to substitute it with your JSON data for the actual PDF generation.

Click on the “Validate and Format JSON” button to format your JSON data.

There are 2 modes of JSON:

  • JSON mode – editable
  • Viewer mode – non-editable
JSON mode: JSON
JSON mode: Viewer

5. Settings Tab

This is where you configure the paper format, page margin, etc.

6. Integrations

CraftMyPDF supports integration with Zapier, Integromat, and REST API

6.1 REST API

API Reference

6.2 Zapier

6.3 Integromat

Table of Contents

Recent Posts
guide
CraftMyPDF

Teams

The teams feature is a shared workspace that allows you to collaborate and get things done in your organization, it’s much easier to share templates with your team.

Read More »
blog
CraftMyPDF

How to create mail merge PDF automatically

In the first part of this tutorial, we will briefly introduce what’s mail merge and the components of mail merge. In the second part, we are going to walk you through the steps to automate the process of mail merging into PDF.

Read More »
blog
CraftMyPDF

How to Make a Barcode in PDF

In this article we talk about what is a barcode, history of barcodes, use-cases, benefits and also how to create barcode in PDF with CraftMyPDF.

Read More »
blog
CraftMyPDF

How to Make a QR Code in PDF

Having QR codes in PDF is a handy thing in your business that can serve multiple purposes. You can share more information about your company or portfolio while sending a PDF proposal. If you wonder how to make a QR code in PDF, we’ve got you covered.

Read More »
guide
CraftMyPDF

CraftMyPDF’s Components for PDF Editor

The PDF template editor consists of a rich set of components for you to build beautiful PDFs with powerful expressions, page-breaks and data-bindings. In this article, we will cover all the components in the PDF designer.

Read More »
Copyright ©2022 CraftMyPDF.com

Email us at hello@craftmypdf.com for support