ThePostman Posted September 11, 2014 Share Posted September 11, 2014 I'm trying to use a background in my PDF invoices. However I do not get any output. Based on the TCPDF documentation (http://www.tcpdf.org/examples/example_051.phps) I used this code in invoicepdf.tpl to insert a background: <?php # Logo background (A4 size) $pdf->Image(ROOTDIR.'/images/invoicebackground.png', 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0); $pdf->setPageMark(); # Invoice Status ... After about a minute the script ends without showing any output. After turning on extra PHP logging I got this error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 7440 bytes) in /home/whmcs/public_html/includes/classes/TCPDF/tcpdf.php on line 7269 I think this implies a memoryleak, but I'm not sure how to proceed. The PNG I'm working with is less then 90Kb. Has anyone got this working with a background? 0 Quote Link to comment Share on other sites More sharing options...
mbit Posted September 11, 2014 Share Posted September 11, 2014 Have you tried using some other image file or JPEG format? Also, there are two rules you need to think about when using image backgrounds in TCPDF: 1. always set your background image before you call any of the writing functions, like WriteHTML, Multicell and so on 2. always call the setPageMark() function after you set your background image Since you're setting your background image inside the invoice template itself, have in mind that the Header() function executes first...do you use the Header() function? If so, set your bg image inside the Header() function. If nothing else works, try upgrading your TCPDF files? 0 Quote Link to comment Share on other sites More sharing options...
ThePostman Posted September 11, 2014 Author Share Posted September 11, 2014 I've done some extra debugging. The problem seems to house in the alpha channel processing of PNG backgrounds. I've made two changes. First of all I've made a PNG image without transparency (alpha). I still prefer the PNG option over JPG as the files only get bigger and PDF generation on the server increases with JPG. However JPG also works. Secondly I've used some new invoicepdf.tpl code due to weird margins being printed in the invoice (which results in the background not filling the page: ----------------- # Logo background $bMargin = $pdf->getBreakMargin(); $auto_page_break = $pdf->getAutoPageBreak(); $pdf->SetAutoPageBreak(false, 0); $pdf->Image(ROOTDIR.'/images/invoicebackground-noalpha.png', 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0); $pdf->SetAutoPageBreak($auto_page_break, $bMargin); $pdf->setPageMark(); ------------------ I would have to test if this works on multipage invoices, but for now the issue seems solved for my (single page) invoices. 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.