Jump to content

Adding a header & footer to invoicepdf.tpl


Tapeix

Recommended Posts

As documented here, it's now possible to add a header and footer to invoicepdf.tpl. (--> http://docs.whmcs.com/PDF_Invoice#Header.2FFooter)

 

Can someone show me an example to reference the header in invoicepdf.tpl? Simply adding invoicepdfheader.tpl to the template directory does not include the header in the actual invoice. The default invoice included with template SIX does not contain any references to the header/footer template. (--> https://github.com/WHMCS/templates-six/blob/master/invoicepdf.tpl)

 

Thanks! :)

Link to comment
Share on other sites

I think this is one of those situations where you'll have to contact support and see if they can throw you a crumb of information on this... and then let the rest of us know! :idea:

 

if it's possible to do it, I could probably figure it out by trial & error... just like we had to with many functions of v6... but let's allow support to give us a working example first and then we can work from there!

Link to comment
Share on other sites

Here are 2 examples that will place a header and footer in your PDF invoice.

 

HEADER:

 

<?php
/**
* PDF Header Example
* @author  WHMCS Chance
* @see     http://docs.whmcs.com/PDF_Invoice#Header_.26_Footer
*/

$pdf->SetFont($pdfFont, '', 9);

$html .= '<p>WHMCS TEST HEADER</p>';
$pdf->writeHTML($html, true, false, false, false, '');

 

FOOTER:

 

<?php
/**
* PDF Footer Example
* @author  WHMCS Chance
* @see     http://docs.whmcs.com/PDF_Invoice#Header_.26_Footer
*/

$pdf->SetFont($pdfFont, '', 9);

$html .= '<p>WHMCS TEST FOOTER</p>';
$pdf->writeHTML($html, true, false, false, false, '');

 

You can use these to see how it will show, and using the TCPDF link from the docs page to further customize the header and footer to fit your needs.

 

This is what I've got from the support. I'll try it myself tomorrow. :)

Link to comment
Share on other sites

I can confirm this solution works on both single page and multi page invoices, yay. :) That being said, you don't need to add anything to invoicepdf.tpl. Just adding these files to your template directory with the code above is enough to let the magic happen.

 

- invoicepdffooter.tpl

- invoicepdfheader.tpl

 

Enjoy!

 

- - - Updated - - -

 

After doing some tests, it seems that language variables do not work at all in the header/footer template.

 

Both of these codes failed to work.

{$LANG. chamberofcommerce}

'.$_LANG['chamberofcommerce'].'

 

Secondly, I need to set a variable for the second page. E.g. {if second page} $pdf->Ln(14); {/if}. Can someone help me with this? Thanks!

Link to comment
Share on other sites

does the first page use invoicepdfheader.tpl or invoicepdf.tpl ? e.g make their output slightly different and see which it is.

 

if it's using invoicepdf.tpl, then invoicepdfheader.tpl would only be used on page2+... if it's using invoicepdfheader.tpl, then that's more complicated...

Link to comment
Share on other sites

does the first page use invoicepdfheader.tpl or invoicepdf.tpl ? e.g make their output slightly different and see which it is.

 

The first pages uses invoicepdfheader.tpl. That makes it complicated indeed. Adding $pdf->Ln(14); at the bottom of the header does not make any difference to the invoice output at all.

Link to comment
Share on other sites

this works fine in v6.2.2 using a single-page invoice... and setting the if statement to check for = "1"...

 

$currentpage = $pdf->getAliasNumPage();
$totalpages = $pdf->getAliasNbPages();

if ($currentpage = "2") {
$html="This is Page ".$currentpage." of ".$totalpages;
$pdf->writeHTML($html, true, false, false, false, '');
}

 

if it doesn't work, then drop the if and just use the four $ lines of code to see if there's any output.

Link to comment
Share on other sites

let's be positive here - it's working, just not 100% :)

 

what about using a counter?

 

$currentpage = $pdf->getAliasNumPage();
$totalpages = $pdf->getAliasNbPages();
$a++;

if ($a = "2") {
$html="This is Page ".$a." of ".$totalpages;
$pdf->writeHTML($html, true, false, false, false, '');
}

Link to comment
Share on other sites

this reminds me of the navbar hooks when v6 was released... fumbling around trying to get things to work with little/no/dodgy documentation to work with. :roll:

surely it should be obvious to WHMCS to either include working example templates or make the documentation clearer.

 

how basic are you making the header code? e.g there isn't a problem with your layout code rather than something wrong with how WHMCS is handling it.

Link to comment
Share on other sites

how basic are you making the header code? e.g there isn't a problem with your layout code rather than something wrong with how WHMCS is handling it.

 

Even if I use the example WHMCS has send, the solution you have provided still not works. I'll try to reach out to WHMCS to get more assistance. Keep this topic updated.

Link to comment
Share on other sites

Even if I use the example WHMCS has send, the solution you have provided still not works. I'll try to reach out to WHMCS to get more assistance. Keep this topic updated.

let me know what WHMCS say because this is starting to intrigue me... i'm currently resisting the urge to have a closer look at this, but I don't know how long I can stop myself! :twisted:

Link to comment
Share on other sites

So as I expected, you do not need to place
 block tags since this is already PHP.

 

I was able to get this to work for me just fine:

 

$currentpage = $pdf->getAliasNumPage();

if ($currentpage == '2') {

$pdf->Ln(14);

}

Also, notice you have only had a single = in the original if statement, so this is going to evaluate the variable to 2 or true and therefore silently error.

 

I just received this message from the support team. I'll try it tomorrow. I haven't received answer about how to add language variables to the header, but since the {if} tags are finally working (according to this message), I will be able to create two different headers (with each its own language/layout) without any hassle. :) keep you updated!

Link to comment
Share on other sites

Didn't work out. Either the code and the language variables are not being passed to the invoice header.

 

if ($language == 'English') {

 

Even the code above displays a blank header. Very disappointing from WHMCS to introduce a new feature that actually should stay in beta yet.

Link to comment
Share on other sites

Didn't work out. Either the code and the language variables are not being passed to the invoice header.

 

if ($language == 'English') {

 

Even the code above displays a blank header.

are you defining what the $language variable is - or are you assuming that it exists?

you could try using $clientdetails in your if statement...

 

if ($clientsdetails["language"] == 'english') {

languages tend to be lowercase in WHMCS, so try 'english' instead of 'English'.

 

i'm assuming you must have access to $clientdetails, otherwise the whole invoice process would be very limited!

if memory serves, if the client's language is set to "Default", then no language value is passed - so be aware of that.

under those circumstances, you could query the lang variable and get the 'locale' value - that could be another viable method to tell what the language is..., e.g "en_GB" - assuming it's even passing the language variables. :roll:

 

if ($_LANG['locale'] == 'en_GB') {
$pdf->writeHTML($_LANG['locale'], true, false, false, false, '');
}

 

Very disappointing from WHMCS to introduce a new feature that actually should stay in beta yet.

disappointing... yet not very surprising - the more things change, the more they stay exactly the same. :mad:

Link to comment
Share on other sites

Your second solution did not help, but your first fortunately did. :)

 

Since the default language is English, I have made this code:

 

if ($clientsdetails["language"] == 'dutch') { dutch text } else { english text }

 

Works excellent! :)

 

I have tried to reduce the size of my header a bit, by reducing the size of the logo. The header now attaches to the content below on the second page. Fortunately, a multi-page invoice is not something that is send frequently to customers, so I can live with that. Until WHMCS has released a proper documentation, I don't want to bother me too much.

 

Thanks for your help, Brian! Very appreciated.

 

p.s. in the past days, I have tried 'English' and 'english' in your variables. Both of them did not work. But I can confirm it has to be written in lowercase.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated