Jump to content

Invoice page number


Lek

Recommended Posts

Hi,

sometimes I have many items on an invoice and the invoice became longer than 1 page. That's fine. But I need a page number somewhere on the top if possible that says: "page 1 of 3" for example. It is mandatory by law here if more than one page. It is possible?

I think should modify the invoice template.

Thank you, bye.

Lek

Link to comment
Share on other sites

  • 2 months later...

Do you mean when a customer is viewing the invoice online or in the generated PDF?

 

Any PDF viewer should display the number of pages by default.

 

Do you know how many lines it takes to be in a second page? I ask this because based on this maybe you could just add a manual item with value $0 called PAGE 2 or something similar into the invoice. Not fancy but would work. Or maybe this can be coded into the invoice expect I see a big problem with your numbering pages invoice approach here. How do you know on which device the user is viewing the invoice? You don't know the screen resolution the user has and so you don't know how many pages the invoice will take. Someone with a vertical monitor could be viewing the full invoice in one 1 single page while a mobile users in 10 pages. This depends completely on the type of screen resolution the person is viewing the invoice.

Link to comment
Share on other sites

Hi, thank you for your replay.

The problem is not when the customer see the invoice on the screen, that can be vary, but when they print as pdf (download as pdf). In that case if the invoice has more than one page there is no note that state how many pages are in total so, officially, the invoice can end at the end of the first page. I could in the first page add an item: "Page one of two" with price = 0 and in the second page another item "page 2 of 2" with price = 0. ...not so fancy...

But I was thinking if the pdf generated with the invoice template can automatically insert the number of page of the file in the format "page 1 of 2", "page 2 of 2". Like in Word for example when you insert page number and automatically more the file is long the page number of pages will be reported.

let me know if any idea.

Bye, Lek

Link to comment
Share on other sites

if you're talking about v7, then one way that you can do it is to use a custom header/footer template...

 

http://docs.whmcs.com/PDF_Invoice_Customisation#Header_.26_Footer

 

if you want to add the output to the header, then you create a 'invoicepdfheader.tpl' template in the same directory as your invoicepdf.tpl template; similarly, if you want the output in the footer, you create an invoicepdffooter.tpl template...

... or, if feeling kinky, use both! :)

 

add the following code into the additional templates...

 

<?php
$currentpage = $pdf->getAliasNumPage();
$totalpages = $pdf->getAliasNbPages();

$pdf->SetFont($pdfFont, '', ;
$pdf->Cell(180, 4, Lang::trans('page') . ' ' . $currentpage . ' ' . Lang::trans('pageof') . ' ' . $totalpages, 0, 1, 'C');

 

g7u8HsH.png

 

obviously, you can modify the output as you wish - e.g., changing 'C' to 'L' or 'R' which aligns the text center, left or right... or perhaps to throw the output into a table cell.

Link to comment
Share on other sites

Hi, it sounds good and exactly what I need. But what about my Version: 6.3.1? Can i do the same?

no - the header/footer additional templates were introduced with v7.

 

if you wanted to add a footer, the quick way would be to add the code below to your template...

 

$pdf->setPrintFooter(true);

and you'd see something like this at the bottom of the page...

Gsz0pY7.png

it's worth knowing that the output will not be multilingual - so it will say "page" whether the client is using English or any other language.

 

of course, it can be modified by editing tcpdf.php, but bear in mind that file is nearly 1MB in size with 25,000 lines of code! - so it's not for the faint-hearted!

 

nCFZtMV.png

if you wanted to do the same for the header, then I think you're into some serious modification - perhaps even modifying the header function itself in tcpdf.php :roll:

 

I don't think that i've ever been asked about that here, or even by a paying client - so i'd file it under the heading: "it can be done, but would be an absolute pain to attempt it!". :)

Link to comment
Share on other sites

Hi, thank you for your easy suggestion.

I applied it and I saw the "page 2/2" but only at the end of the second page.

So what I did (no pain road) was also to add the footer in the header... :

# Header Bar
$pdf->SetFont($pdfFont, 'B', 15);
$pdf->SetFillColor(239);
$pdf->Cell(0, 8, $pagetitle, 0, 1, 'L', '1');
$pdf->SetFont($pdfFont, '', 10);
$pdf->Cell(0, 6, Lang::trans('invoicesdatecreated') . ': ' . $datecreated, 0, 1, 'L', '1');
$pdf->Cell(0, 6, Lang::trans('invoicesdatedue') . ': ' . $duedate, 0, 1, 'L', '1');
$pdf->Ln(10);

$startpage = $pdf->GetPage();
# Here my add:
$pdf->setPrintFooter(true);  

# Clients Details

So now I have page 1/2 in first page

page1of2.jpg

and page 2/2 in the second page

page2of2.jpg

It works! It does not matter is only English. Eventually I can modify the word page and add a second word.

Any known side effect of this footer in the header?

Waiting for comments.

Bye,

Lek

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated