Invoice page num and total pages for PDF version

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:
pagina di


and then, in the "PDF and email styles" box,
#myfooter {
position: fixed;bottom: 0px; right: 5px; text-align:right; font-size:8px; counter-increment:pages;}
#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

Wednesday, December 09 2015, 05:58 PM - #Permalink
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:
//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
The reply is currently minimized Show
Responses (7)
  • Accepted Answer

    Monday, December 07 2015, 11:24 AM - #Permalink
    0
    that'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?
    The reply is currently minimized Show
  • Accepted Answer

    Wednesday, December 09 2015, 11:40 AM - #Permalink
    0
    Hello 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
    The reply is currently minimized Show
  • Accepted Answer

    Wednesday, December 09 2015, 05:49 PM - #Permalink
    0
    Hello!

    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...
    The reply is currently minimized Show
  • Accepted Answer

    Wednesday, December 09 2015, 06:39 PM - #Permalink
    0
    Great!! It works!! Thanks a lot for your help and time!
    The reply is currently minimized Show
  • Accepted Answer

    Sunday, February 03 2019, 03:54 PM - #Permalink
    0
    Hi, how can i enable php in new version?
    • Germinal Camps
      more than a month ago
      what you mean? the same code doesn't work?
    The reply is currently minimized Show
  • Accepted Answer

    Tuesday, February 05 2019, 09:03 PM - #Permalink
    0
    Can't find "define("DOMPDF_ENABLE_PHP", true)" code in dompdf. How can i enable php in dompdf?
    The reply is currently minimized Show
  • Accepted Answer

    Monday, February 11 2019, 09:33 AM - #Permalink
    0
    sorry, the current vesion you have to do this:
    open file /components/com_invoices/views/invoice/view.dompdf.php
    around line 83 you find this:

    $options->set( 'isRemoteEnabled', TRUE );


    you have to add this:

    $options->set( 'isRemoteEnabled', TRUE );
    $options->set( 'isPhpEnabled', TRUE );
    The reply is currently minimized Show
Your Reply