Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPDF page number in HTML #172

Closed
ghost opened this issue Jul 6, 2016 · 12 comments
Closed

MPDF page number in HTML #172

ghost opened this issue Jul 6, 2016 · 12 comments

Comments

@ghost
Copy link

ghost commented Jul 6, 2016

Hello,

Currently I'm creating a template system, and we are using MPDF to generate the PDF versions of the templates, so far this has been great. But the only problem that we are having is that the page numbering tags do not get replaced in the WriteHTML block, but this is something that we would like to have. Is it in any way possible to get this working with a setting that I have missed?

Bob

@finwe
Copy link
Member

finwe commented Jul 6, 2016

The Issue template is not here for nothing. Provide a minimal, complete, and verifiable example for your usecase, including your setup and library versions.

@finwe
Copy link
Member

finwe commented Jul 10, 2016

Feel free to reopen with the additional information.

@finwe finwe closed this as completed Jul 10, 2016
@jochenwezel
Copy link

I assume some reproduction code as following

<?php

require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('Page {PAGENO} of {nb}');
$mpdf->Output();
?>

Current output:

Page {PAGENO} of {nb}

Requested output:

Page 1 of 1

Solved with MPDF 6.1 as following

Changed function _puthtmlheaders() in mpdf.php: Added code block "Replace page no and total pages number variables in body of every page"

                                }
                                /* -- FORMS -- */
                                foreach ($this->HTMLheaderPageForms AS $f) {
                                        $f['y'] += $adj;
                                        $this->mpdfform->forms[$f['n']] = $f;
                                }
                                /* -- END FORMS -- */
                        }

                        // Replace page no and total pages number variables in body of every page
                        $this->pages[$n] = str_replace(mb_convert_encoding('{PAGENO}', 'UTF-16', 'UTF-8'), mb_convert_encoding($pnstr, 'UTF-16', 'UTF-8'), $this->pages[$n]);
                        $this->pages[$n] = str_replace(mb_convert_encoding($this->aliasNbPgGp, 'UTF-16', 'UTF-8'), mb_convert_encoding($pntstr, 'UTF-16', 'UTF-8'), $this->pages[$n]); // {nbpg}
                        $this->pages[$n] = str_replace(mb_convert_encoding($this->aliasNbPg, 'UTF-16', 'UTF-8'), mb_convert_encoding($nb, 'UTF-16', 'UTF-8'), $this->pages[$n]); // {nb}

                }
                $this->page = $nb;
                $this->state = 1;
        }

@finwe
Copy link
Member

finwe commented Apr 9, 2019

This is intended and documented behaviour. Page patterns are being replaced in headers and footers only.

@jochenwezel
Copy link

The requested behavious is (at least from my side) to support it in body, too.
An "intendation" that this must not happen in body wouldn't be understandable.

@martijnpieters
Copy link

I'd also like to have the feature as proposed by @jochenwezel.

@finwe Should I open a PR with the above mentioned solution, or is there a serious blocker over here (based on the help wanted label)?

@davidvanvan
Copy link

davidvanvan commented Sep 11, 2019

any update on this possible feature? I am actually using his sulotion, with version 8.0, and it is working

@davidvanvan
Copy link

I'd also like to have the feature as proposed by @jochenwezel.

@finwe Should I open a PR with the above mentioned solution, or is there a serious blocker over here (based on the help wanted label)?

Have you created a PR good sir? I think this feature proposed by @jochenwezel is great

@jochenwezel
Copy link

I solved it in my environment in mpdf.php in function _puthtmlheaders() with following code (approx. line 9728). If somebody could review it (especially for right version) and create a patch for for this ticket, I'd appreciate it :-)

<?php

// ******************************************************************************
// Software: mPDF, Unicode-HTML Free PDF generator                              *
// Version:  6.1        based on                                                *
//           FPDF by Olivier PLATHEY                                            *
//           HTML2FPDF by Renato Coelho                                         *
// Date:     2016-03-25                                                         *
...
						$by = $this->w - $ax;
						$lk[0] = $bx * _MPDFK;
						$lk[1] = ($this->h - $by) * _MPDFK - $lw;
					}
					$this->PageLinks[$n][] = $lk;
				}
				/* -- FORMS -- */
				foreach ($this->HTMLheaderPageForms AS $f) {
					$f['y'] += $adj;
					$this->mpdfform->forms[$f['n']] = $f;
				}
				/* -- END FORMS -- */
			}
			
			// Customization for https://github.com/mpdf/mpdf/issues/172
                        // Replace page no and total pages number variables in body of every page
                        $this->pages[$n] = str_replace(mb_convert_encoding('{PAGENO}', 'UTF-16', 'UTF-8'), mb_convert_encoding($pnstr, 'UTF-16', 'UTF-8'), $this->pages[$n]);
                        $this->pages[$n] = str_replace(mb_convert_encoding($this->aliasNbPgGp, 'UTF-16', 'UTF-8'), mb_convert_encoding($pntstr, 'UTF-16', 'UTF-8'), $this->pages[$n]); // {nbpg}
                        $this->pages[$n] = str_replace(mb_convert_encoding($this->aliasNbPg, 'UTF-16', 'UTF-8'), mb_convert_encoding($nb, 'UTF-16', 'UTF-8'), $this->pages[$n]); // {nb}
			// /Customization for https://github.com/mpdf/mpdf/issues/172

		}
		$this->page = $nb;
		$this->state = 1;
	}

	function _putpages()
	{
		$nb = $this->page;
		$filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
...

@jochenwezel
Copy link

jochenwezel commented Oct 2, 2019 via email

@fsmalaquias
Copy link

Any update ?

@finwe
Copy link
Member

finwe commented Apr 5, 2022

Closing as resolved in mentioned issue.

@finwe finwe closed this as completed Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants