5. Customization template

1. Create a new theme

Follow these instructions

  1. Create a new “my_theme” directory in /media/GlobalPDF/
  2. Copy all /media/GlobalPDF/default files in your “my_theme” directory
  3. Enable your theme in System > Configuration > Global pdf > Theme

Note

Here my_theme is your custom theme name.

2. Templates

Templates are xml files used to generate the PDF files, and located by default in /media/GlobalPdf/default

  • header.xml : template for all pdf header
  • footer.xml : template for all pdf footer
  • shipment.xml : template for packing slip pdf
  • product.xml : template for product pdf
  • order.xml : template for order pdf
  • invoice.xml : tempate for invoice pdf
  • creditmemo.xml : template for creditmemo pdf
  • catalog.xml : template for the first product catalog page
  • cart.xml : template for cart pdf

3. Syntax rules

  • {xxx} : used to print a dynamic value.

For example, {name} return product name in the product PDF.

  • [xxx] : used to translate a label.

For example, [invoice] will be converted to “facture” if website is in french.

4. Template Items

You can use items in templates to draw picture, rectangle, text... Here are the different available items :

Rectangle

  • Description : Draw a rectangle

  • Attributes :
    • border : border size
    • bordercolor : border color
    • bgcolor : background color
  • Sub items : zindex, position, size

Text

  • Description : Draw a single text

  • Attributes :
    • value : text to draw
  • Sub items : zindex, position, size, font

Img

  • Description : insert a picture

  • Attributes :
    • src : picture server path
    • mode : “Zoom” keep product proportion, use “shrink” to fit picture to area
  • Sub items : zindex, position, size

If

  • Description : Draw items if condition is true

  • Attributes :
    • condition : condition to test (you can use {values} operator : comparison type : use “neq” for different, “eq” for equal
    • value : value to compare in condition
  • Sub items :all items

Method

  • Description : Call a PDF function

  • Attributes :
    • name : method to call : increment_y, increment_x, set_x, set_y, set_store, set_footer_height
    • value : method parameter
  • Sub items : none

Multitext

  • Description : Draw multi line text

  • Attributes :
    • value : text to print increment_y : if 1, the system will increase y value using text height
    • max_lines : max lines to draw
  • Sub items : zindex, position, size, font

Repeater

  • Description : Used to loop on collection (for example, used to print order items)

  • Attributes :
    • source : collection to use
    • max_occurences : max time to loop
  • Sub items :all items

5. Edit template

Note

It’s highly recommended to create a new custom theme instead of edit the default Global PDF theme.

Add an image into a PDF

  1. Edit the php file of the desired PDF like, for example app/code/community/MDN/GlobalPDF/Model/Pdf/Order/Invoice.php
  2. Add following code
$data['my_image'] = '/your_complete_ftp_path/skin/frontend/[theme]/[design]/images/image.png';

Where [theme]/[design] are the theme and design folders of your actual magento template.

before the line

return data;

Note

You can rename “image.png” to put your own image name.

  1. Go into the targeted XML file like invoice.xml then add this code :
<img src="{my_image}" mode="zoom">
     <zindex value="1" />
     <position lef="320" top="20" mode="relative" />
     <size width="260" height="90" />
</img>

Manage a new page

Two possibilities if you want to manage a new page into the targeted XML like invoice.xml

  1. Allow a multitext zone to go to the next page if it grows too.
  2. Check the Y position, and get on the next page.

6. Add a variable

Let’s say, we want to add a new variable in the invoice PDF.

Edit app/code/community/MDN/GlobalPDF/Model/Pdf/Order/Invoice.php

Search for setTemplateData function and add inside:

$data['my_custom_data'] = //some code

Then in the XML file, media/GlobalPdf/default/invoice.xml

You will be able to use the new variable with {my_custom_data}