Tapeix Posted October 11, 2016 Share Posted October 11, 2016 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! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 11, 2016 Share Posted October 11, 2016 are you trying it on a multi-page PDF invoice - the documentation implies it would only apply to them. 0 Quote Link to comment Share on other sites More sharing options...
Tapeix Posted October 11, 2016 Author Share Posted October 11, 2016 Nope, it is not that easy. I have tried this solution with one page and multi-page invoices. Both does not contain a header/footer on the first or the second page. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 12, 2016 Share Posted October 12, 2016 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! 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! 0 Quote Link to comment Share on other sites More sharing options...
Tapeix Posted October 12, 2016 Author Share Posted October 12, 2016 Okidoki, I will post the solution here once provided. 0 Quote Link to comment Share on other sites More sharing options...
Tapeix Posted October 12, 2016 Author Share Posted October 12, 2016 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. 0 Quote Link to comment Share on other sites More sharing options...
Tapeix Posted October 13, 2016 Author Share Posted October 13, 2016 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! 0 Quote Link to comment Share on other sites More sharing options...
Tapeix Posted October 13, 2016 Author Share Posted October 13, 2016 (edited) First issue has been solved by translating it myself, using smarty tags. if ($language = "English") { } But I still don't have a solution for the second problem. Edited October 13, 2016 by Tapeix 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 13, 2016 Share Posted October 13, 2016 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... 0 Quote Link to comment Share on other sites More sharing options...
Tapeix Posted October 13, 2016 Author Share Posted October 13, 2016 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. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 13, 2016 Share Posted October 13, 2016 try the following in invoicepdfheader.tpl and see if it works as you want it to... $currentpage = $pdf->getAliasNumPage(); if ($currentpage = "2") { $pdf->Ln(14); } 0 Quote Link to comment Share on other sites More sharing options...
Tapeix Posted October 13, 2016 Author Share Posted October 13, 2016 Your solution does not make any difference at all. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 13, 2016 Share Posted October 13, 2016 ok, instead of your ln(14), get it to output some text (or $currentpage) in the if statement and see if the value exists. 0 Quote Link to comment Share on other sites More sharing options...
Tapeix Posted October 13, 2016 Author Share Posted October 13, 2016 No output at all... $currentpage = $pdf->getAliasNumPage(); if ($currentpage = "2") { $html='hello world'; $pdf->Ln(14); } 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 13, 2016 Share Posted October 13, 2016 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. 0 Quote Link to comment Share on other sites More sharing options...
Tapeix Posted October 13, 2016 Author Share Posted October 13, 2016 This code doesn't work either. It says 'This is Page 2 of 2' on both pages. Removing the [if] tags does fix the issue with $currentpage, on page 1 it simply says '1' instead of '2'. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 13, 2016 Share Posted October 13, 2016 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, ''); } 0 Quote Link to comment Share on other sites More sharing options...
Tapeix Posted October 13, 2016 Author Share Posted October 13, 2016 Nope, same output. Page 1 is defined as page 2, page 2 is defined as page 2. I don't get it. But my main problem is: the header is overlapping content on the second page. This should be solved. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 13, 2016 Share Posted October 13, 2016 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. 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. 0 Quote Link to comment Share on other sites More sharing options...
Tapeix Posted October 14, 2016 Author Share Posted October 14, 2016 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. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 14, 2016 Share Posted October 14, 2016 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! 0 Quote Link to comment Share on other sites More sharing options...
Tapeix Posted October 14, 2016 Author Share Posted October 14, 2016 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! 0 Quote Link to comment Share on other sites More sharing options...
Tapeix Posted October 15, 2016 Author Share Posted October 15, 2016 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. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 15, 2016 Share Posted October 15, 2016 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. 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. 0 Quote Link to comment Share on other sites More sharing options...
Tapeix Posted October 15, 2016 Author Share Posted October 15, 2016 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. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.