0
Hi,
I would like to add a footer on each page of my invoices, reporting the current page number over the total pages number (for instance, "page 1 of 3", "page 2 of 3", etc. I want this just for PDF version of template.
I customized the invoice template adding following div before all the already existent divs:
and then, in the "PDF and email styles" box,
#myfooter {
position: fixed;bottom: 0px; right: 5px; text-align:right; font-size:8px; counter-incrementages;}
#pagenum:before { content: counter(page); }
#pagetotal:before { content: counter(pages); }
I can see just "page 1 of 1", "page 2 of 2", etc.
I tried also not to increment "pages" counter, since it should be a css predefined counter...in that case I see "page 1 of 0", "page 2 of 0" and so on... it seems counter(page) works, counter(pages) doesn't work.
Am I wrong on something? Is there a way, inside the extension itself, that can allow me to set the pages number and total?
Thank you
I would like to add a footer on each page of my invoices, reporting the current page number over the total pages number (for instance, "page 1 of 3", "page 2 of 3", etc. I want this just for PDF version of template.
I customized the invoice template adding following div before all the already existent divs:
and then, in the "PDF and email styles" box,
#myfooter {
position: fixed;bottom: 0px; right: 5px; text-align:right; font-size:8px; counter-incrementages;}
#pagenum:before { content: counter(page); }
#pagetotal:before { content: counter(pages); }
I can see just "page 1 of 1", "page 2 of 2", etc.
I tried also not to increment "pages" counter, since it should be a css predefined counter...in that case I see "page 1 of 0", "page 2 of 0" and so on... it seems counter(page) works, counter(pages) doesn't work.
Am I wrong on something? Is there a way, inside the extension itself, that can allow me to set the pages number and total?
Thank you
Accepted Answer
0
waaait!! I made it work.
There's a variable that needs to be enabled. Please follow the next steps:
1. open file /components/com_muscol/com_invoices/helpers/dompdf/dompdf_config.custom.inc.php
in line 10 you will see this commented line:
You must uncomment it, that is, remove the two slashes at the beginning:
2. open on your TEMPLATE (for your invoice) on Invoice Manager backend, and on the "PDF and email version" tab, add this bit of code at the end of the main code area:
You're good to go. It works for me! At the right bottom corner of each page you will get the counter like this: 1/3, 2/3, etc
if you want to change the format of this counter, it's just this part of the code, which is pretty self-explanatory:
it's the '{PAGE_NUM}/{PAGE_COUNT}' part
you can change it for example for:
'page {PAGE_NUM} of {PAGE_COUNT}'
or whatever you like
There's a variable that needs to be enabled. Please follow the next steps:
1. open file /components/com_muscol/com_invoices/helpers/dompdf/dompdf_config.custom.inc.php
in line 10 you will see this commented line:
//define("DOMPDF_ENABLE_PHP", true);
You must uncomment it, that is, remove the two slashes at the beginning:
define("DOMPDF_ENABLE_PHP", true);
2. open on your TEMPLATE (for your invoice) on Invoice Manager backend, and on the "PDF and email version" tab, add this bit of code at the end of the main code area:
<script type='text/php'>
if ( isset($pdf) ) {
$font = Font_Metrics::get_font('helvetica', 'normal');
$size = 9;
$y = $pdf->get_height() - 24;
$x = $pdf->get_width() - 15 - Font_Metrics::get_text_width('1/1', $font, $size);
$pdf->page_text($x, $y, '{PAGE_NUM}/{PAGE_COUNT}', $font, $size);
}
</script>
You're good to go. It works for me! At the right bottom corner of each page you will get the counter like this: 1/3, 2/3, etc
if you want to change the format of this counter, it's just this part of the code, which is pretty self-explanatory:
$pdf->page_text($x, $y, '{PAGE_NUM}/{PAGE_COUNT}', $font, $size);
it's the '{PAGE_NUM}/{PAGE_COUNT}' part
you can change it for example for:
'page {PAGE_NUM} of {PAGE_COUNT}'
or whatever you like
Responses (7)
-
Accepted Answer
0that's a tricky one.
what you did looks quite very good (good work!), but for some reason it looks like it's not counting the pages correctly. this would be because of the HTML to PDF conversion, it could be that is not counting the pages correctly. This would work in CSS but the PDF transformation does its own calculations so it's possible that this will not work.
I've been looking around, and what some people does it to use a script of type text/php to actually execute a code to calculate the page, given that the CSS calculation seems to not be working properly.
see this: http://stackoverflow.com/questions/13159645/dompdf-page-number
could that help? -
Accepted Answer
0Hello Germinal,
thanks for your feedback. Unfortunately, I am not able to understand this solution at 100%, since I do not know php code well.
Actually I do not know what to do: shall I create a new php file? in which folder? What name shall have this file? Do I need to "link" it at other dompdf already existent file?
Regards -
Accepted Answer
0Hello!
no, this was not intended for you to create a new file. The idea is that if you add this code (the text/php script) into the TEMPLATE code, it could help do the pagination.
I've been trying this tho and for now I can't seem to get it working... although in that page it says it works. I will keep trying.
for now I'm afraid the only way for you will be to "hardcode" de number of pages directly in the template... -
Accepted Answer
0Hi, how can i enable php in new version?-
Germinal Campsmore than a month agowhat you mean? the same code doesn't work?
-
-
Accepted Answer
-
Accepted Answer
Your Reply
Please login to post a reply
You will need to be logged in to be able to post a reply. Login using the form on the right or register an account if you are new here.
Register Here »