-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Comments
The Issue template is not here for nothing. Provide a minimal, complete, and verifiable example for your usecase, including your setup and library versions. |
Feel free to reopen with the additional information. |
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:
Requested output:
Solved with MPDF 6.1 as followingChanged 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;
} |
This is intended and documented behaviour. Page patterns are being replaced in headers and footers only. |
The requested behavious is (at least from my side) to support it in body, too. |
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 |
any update on this possible feature? I am actually using his sulotion, with version 8.0, and it is working |
Have you created a PR good sir? I think this feature proposed by @jochenwezel is great |
I solved it in my environment in mpdf.php in <?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 ' : '';
... |
Since Mpdf.php of v7 has been redesigned completely, I can’t quickly find the missing piece.
I solved it by stepping through the code with some debugging and finally found a code location to fix it.
Von: nicklongo <notifications@github.com>
Gesendet: Mittwoch, 2. Oktober 2019 11:31
An: mpdf/mpdf <mpdf@noreply.github.com>
Cc: Jochen Wezel - CompuMaster GmbH <jwezel@compumaster.de>; Mention <mention@noreply.github.com>
Betreff: Re: [mpdf/mpdf] MPDF page number in HTML (#172)
Sorry @jochenwezel<https://github.com/jochenwezel> but your solution doesn't work in my mpdf.php (Version 7)
in this version _putpages() function is replaced by writePages() function in PageWriter.php .
Maybe the problem is not there, but after adding your
// Customization for #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 #172
in mpdf.php file, and after upload file on server, {nb} or {PAGENO} or {nbpg} remain in the "String" mode.
Could you please tell me what could be wrong with Mpdf 7?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#172?email_source=notifications&email_token=AAXEVYZ6QRINIA4I5ULPWWDQMRS6TA5CNFSM4CIYNEC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAEEXBQ#issuecomment-537414534>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AAXEVYZZEWNYRYDDMY4KAHTQMRS6TANCNFSM4CIYNECQ>.
|
Any update ? |
Closing as resolved in mentioned issue. |
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
The text was updated successfully, but these errors were encountered: