Forum


Replies: 3   Views: 363
Is it possible to inject the number of pages and page number with embedhtml
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by jake@dewittsolutions.com  · 12-01-2024 - 21:32

Hi I am wanting to embed the number of pages and current page number into the header (and maybe even the footer) of a document using the embedHTML(). PHPOffice has done something similar to this with thier {PAGE} and {NUMPAGES} constants. I am curious if the same thing can be accomplished with PHPDocx but adding it specifically within a block of HTML that I then embed into the header for example the code might look something like this:
 

$docx = new CreateDocx();
$headerHTML = '<div>Page {PAGE} of {NUMPAGES}</div>';
$headerFragment = new WordFragment($docx, 'defaultHeader');
$headerFragment->embedHTML($headerHTML);
$docx->addHeader(['default' => $headerFragment]);

$html = '<h1>Document Content</h1>'
$docx->embedHTML($html);
$docx->createDocx('path/to/file.docx');