Looking back at this there is one problem. If you declare $GLOBALS['attachments'] using normal inline script it will always be set to whatever the last value when the page_script() is run. This is because inline script is executed as the document is parsed, while page_script() is stored during document parsing and subsequently run on every page of the document
after the entire document has been parsed. So instead of true you should indicate what page the attachments start on. Then this modified code logic should work.
<script type="text/php">
if (isset($pdf) ) {
$pdf->page_script('
if ( $PAGE_COUNT > 10 && $PAGE_NUM == 1) {
//front page footer
} elseif ($PAGE_NUM == $GLOBALS['attachments']) {
//attachments actions
} else {
//other pages' header and footer
}
');
}
</script>
I hope that works better for you.
FYI, the nightly download is currently out of date. It still pulls from our old SVN repository, which is behind by a bit. To try out the latest code head over to our github project pages and click on the "zip" button near the top of the page. It's a bit inconvenient because you have to download php-font-lib separately.
dompdf
https://github.com/dompdf/dompdfphp-font-lib
https://github.com/PhenX/php-font-libOn Sunday, March 10, 2013 6:22:14 PM UTC-4, Sean Kelly wrote:
Hi Brian, please forgive me for jumping in on an older ticket but I wonder if you have a moment to please clarify your explanation above?
When I declare $GLOBALS['attachments'] "true" near the bottom of my page-to-be-printed, it is applied to all of my pdf pages instead of just the last ones with attachments.
I know that my conditional code inside page_script() is working by setting the attachments to false and headers/footers are inserted into all of my pdf pages.
In my page, I have three blocks of <script type="text/php"> code for Dompdf to parse.
1) Page numbers on all pages. I also set $GLOBALS['attachments'] to false in this block at the top of my page.
2) page_script() code with conditional statement as in your example.
3) A small block just before I add my file attachments that sets the $GLOBALS['attachments'] variable to true.
Any suggestions you might have would be greatly appreciated.
Regards,
Sean