Jump to content

PDF page numbers


Recommended Posts

Hello,

 

As I see PS 1.5 uses TCPDF to generate PDF invoices. In default there is no page numbers in invoices when invoice is larger than 1 page (or I don't see the option for it).

The question - is there any easy way to add these vales to PDF footer? I looked at the generator and other files and don't exactly find the solution for it..

 

Thanks!

Link to comment
Share on other sites

i don't see that any page numbers are created no matter how many pages the invoice has.

 

Appears Prestashop has overridden the Footer method in PDFGeneratorCore, and does not include page numbers.

So you would need to further extend PDFGeneratorCore, and then include your logic to produce page numbers

 

This is the default footer method in PDFGeneratorCore, which just displays whatever is in footer.tpl

    public function Footer()
   {
       $this->writeHTML($this->footer);
   }

 

So you would need to include something like this... and then add whatever formatting you would want

    public function Footer()
   {
       $this->writeHTML($this->footer);
       $this->writeHTML('Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages());
   }

 

you can review the default TCPDF Footer function located in tools/tcpdf/tcpdf.php to see how they do it by default, and then include that in your override

  • Like 1
Link to comment
Share on other sites

Hi everyone,

 

Outset, I congratulate the prestashop team for the excellent work that has developed.

 

My question:

After two days around the PDF invoice, tired, can not find any solution to print the table header on the second page of the invoice, or if there is a large order, in which the products are passed to a second page, the client does not can see the titles of the Table (Qty, Description, Price, etc..) which is an important form of guide for the client.

Someone with the same problem?

 

Attached is an example with an invoice with more than one page.

 

Thanks.

Regards,

 

Shark-Distribution

post-525508-0-57110000-1374575187_thumb.jpg

Link to comment
Share on other sites

I suspect you will have to alter the invoice template file, so that it would include the table header.

Prestashop developers likely did not account for real world scenarios like this one.

 

There are probably a few options

1) Update the invoice template so that it if its page 1, create a table with 8 products. If its page 2+, create a table with XX products. You will need to figure out how many products would fit on page 2+, since page 2+ does not contain the address and other header fields, it would be more than 8

 

2) Add code that would detect when a new page is created, and recreate the table

 

I suspect both of these options will be rather difficult, since the smarty template engine does not know what "page" it is currently on.

Link to comment
Share on other sites

After two days around the PDF invoice, tired, can not find any solution to print the table header on the second page of the invoice, or if there is a large order, in which the products are passed to a second page, the client does not can see the titles of the Table (Qty, Description, Price, etc..) which is an important form of guide for the client.

Someone with the same problem?

The M4 PDF Extensions module can do that. There is a template with repeated header already built-in.

  • Like 1
Link to comment
Share on other sites

Unfortunately i can't find any solution.

I found the code snippet below, by the logic should be the solution of my problem, but no.

I appreciate your proposed tuk66, is attractive but we are a company in the initial phase, which we should save the most of the costs, as you calculate.

 

/**
 * This method is used to render the table header on new page (if any).
 * @protected
 * @since 4.5.030 (2009-03-25)
 */
protected function setTableHeader() {
 if ($this->num_columns > 1) {
  // multi column mode
  return;
 }
 if (isset($this->theadMargins['top'])) {
  // restore the original top-margin
  $this->tMargin = $this->theadMargins['top'];
  $this->pagedim[$this->page]['tm'] = $this->tMargin;
  $this->y = $this->tMargin;
 }
 if (!$this->empty_string($this->thead) AND (!$this->inthead)) {
  // set margins
  $prev_lMargin = $this->lMargin;
  $prev_rMargin = $this->rMargin;
  $prev_cell_padding = $this->cell_padding;
  $this->lMargin = $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
  $this->rMargin = $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
  $this->cell_padding = $this->theadMargins['cell_padding'];
  if ($this->rtl) {
   $this->x = $this->w - $this->rMargin;
  } else {
   $this->x = $this->lMargin;
  }
  // account for special "cell" mode
  if ($this->theadMargins['cell']) {
   if ($this->rtl) {
 $this->x -= $this->cell_padding['R'];
   } else {
 $this->x += $this->cell_padding['L'];
   }
  }
  // print table header
  $this->writeHTML($this->thead, false, false, false, false, '');
  // set new top margin to skip the table headers
  if (!isset($this->theadMargins['top'])) {
   $this->theadMargins['top'] = $this->tMargin;
  }
  // store end of header position
  if (!isset($this->columns[0]['th'])) {
   $this->columns[0]['th'] = array();
  }
  $this->columns[0]['th']['\''.$this->page.'\''] = $this->y;
  $this->tMargin = $this->y;
  $this->pagedim[$this->page]['tm'] = $this->tMargin;
  $this->lasth = 0;
  $this->lMargin = $prev_lMargin;
  $this->rMargin = $prev_rMargin;
  $this->cell_padding = $prev_cell_padding;
 }
}

 

 

Someone who can help me?

Thanks.

 

Best regards

 

Shark-Distribution

Link to comment
Share on other sites

  • 1 year later...

i don't see that any page numbers are created no matter how many pages the invoice has.

 

Appears Prestashop has overridden the Footer method in PDFGeneratorCore, and does not include page numbers.

So you would need to further extend PDFGeneratorCore, and then include your logic to produce page numbers

 

This is the default footer method in PDFGeneratorCore, which just displays whatever is in footer.tpl

public function Footer()
    {
        $this->writeHTML($this->footer);
    }
So you would need to include something like this... and then add whatever formatting you would want

public function Footer()
    {
        $this->writeHTML($this->footer);
        $this->writeHTML('Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages());
    }
you can review the default TCPDF Footer function located in tools/tcpdf/tcpdf.php to see how they do it by default, and then include that in your override

 

Hello!

This works good!

Can you help me to make generating of page numbers from the second page? I.E. The first page is like a title without page number and other pages have numbers starting from 1.

Link to comment
Share on other sites

  • 7 months later...

i don't see that any page numbers are created no matter how many pages the invoice has.

 

Appears Prestashop has overridden the Footer method in PDFGeneratorCore, and does not include page numbers.

So you would need to further extend PDFGeneratorCore, and then include your logic to produce page numbers

 

This is the default footer method in PDFGeneratorCore, which just displays whatever is in footer.tpl

public function Footer()
    {
        $this->writeHTML($this->footer);
    }
So you would need to include something like this... and then add whatever formatting you would want

public function Footer()
    {
        $this->writeHTML($this->footer);
        $this->writeHTML('Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages());
    }
you can review the default TCPDF Footer function located in tools/tcpdf/tcpdf.php to see how they do it by default, and then include that in your override

 

Belini, is it possible to assign getAliasNumPage and getAliasNbPages functions results to smarty variables and use as usual in invoice.tpl ? I would like to put page number in correct page. Thanks.

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...