HTML2PDF User manual - Using inline coding

Posted on July 24, 2012 by ext4mage There have been 0 comments

Using inline coding

This is where things get very powerful and a bit complex. If you do not know PHP just a bit, then be careful about which code you type in here.

What you can do with HTML2PDF inline code, is everything from simple math stuff to very complex PHP code. I will here give a short taste of what you can do, but there is a lot of other possibilities. The format of inline coding in HTML2PDF is as follows

## the_code##            //the format
##{order_data_subtotal }}-{{order_data_discount}}##
  //will print the subtotal minus the discount

The above example is very simple, here we just take one value and subtracts another.

The below example from the example template delivered with HTML2PDF is more complex. Here we want to show the picture of a product in the product table, for that we need 2 different variables. The first one is Magento build-in media function (also know from Magento CMS) to get the correct path, and then the products image URL. But before we can render the image we have to check if it exists, otherwise the PDF generator will give an error. The way we do that is  by checking if the product URL has the text  “no_selection” (found by looking in the help page variables), and if it is not equal that we render the image. HTML2PDF User manual - using inline coding example

Not all PHP function can be used. Example: if expression cannot be used, instead use the conditional operator ?: - the eval function is used in HTML2PDF, you can read more about it on

It can be a bit tricky to get the inline code to work, but setting HTML2PDF in development mode can be very useful when creating and testing inline code

Be sure that you are signed up for ext4mage newsletter, because we will be sending out tips and examples of ways to use inline coding.


The HTML2PDF extension for Magento
See more about the magento extension HTML2PDF

This post was posted in Manual and was tagged with html2pdf, magento, pdf, print pdf, manual, inline coding