Javascript

Formatting pdfMachine merge HTML Templates

pdfMachine merge supports using javascript in a HTML template.
Javascript is a procedural language that supports for loops, conditionals, variables and math operations. More info here 

Your HTML template should contain the following special tag:
{{json_here}}

In HTML files, this is substituted with a JSON (JavaScript Object Notation) string containing all the data for that bundle. This allows a you to write javascript that iterates through the data, for calculation or rendering.
For the example mentioned on the bundle page, when the merge starts, 3 HTML files will be generated then converted to PDF. The HTML template file would contain the line:

	var data = {{json_here}};
		
In the case of the file destined for bugs@somefirm.com the above line would become:
	var data = [
		{"email": "bugs@somefirm.com","customer": "Big Jim's Shop","invoice_id":224,"invoice_date": "23/01/2011 12:00:00 AM","item": "black thingy","unit_cost":25,"quantity":1,"amt_due":250},
		{"email": "bugs@somefirm.com","customer": "Big Jim's Shop","invoice_id":224,"invoice_date": "23/01/2011 12:00:00 AM","item": "pink  thingy","unit_cost":25,"quantity":2,"amt_due":250},
		{"email": "bugs@somefirm.com","customer": "Big Jim's Shop","invoice_id":224,"invoice_date": "23/01/2011 12:00:00 AM","item": "red  thingy","unit_cost":25,"quantity":3,"amt_due":250},
		{"email": "bugs@somefirm.com","customer": "Big Jim's Shop","invoice_id":224,"invoice_date": "23/01/2011 12:00:00 AM","item": "blue  thingy","unit_cost":25,"quantity":4,"amt_due":250}
	];
		

Javascript code could then iterate through the data and display it.

For an example of using javascript in a template:
Click here to see an example HTML merge template using javascript.
Click here to see an example of the PDF generated.
When you install pdfMachine merge, a profile is setup with this called "HTML template with bundled emails", which you try out and customize to your requirements. 

When using HTML templates, for best results you will need to set certain print options in Internet Explorer
  • Turn off Internet Explorer print headers and footers by File | Page Setup and change them all to "empty"
  • Turn on background colors for printing by File | Page Setup, tick "Print Background Colors and Images"
If you need help or more information on this feature please contact