Forum


Replies: 3   Views: 3004
Is ti possible to insert new text on a document at the end ?
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 admin  · 01-05-2018 - 08:42

Hello,

As there's no way to get the end of a page by its contents, the only solution is adding sections or page breaks (https://support.office.com/en-us/article/insert-a-section-break-eef20fd8-e38c-4ba6-a027-e503bdf8375c) to each page when you create the DOCX (from scratch or a template); each page must have a page break or a section. Adding one of these breaks (section or page break) and using phpdocx 6.5 or newer (Advanced or Premium licenses) you can query by the section tag (w:sectPr , 'section' type value) to add an element before each section:

$content->addText('New text.', array('fontSize' => 20, 'color' => '#0000ff'));

// as there's no occurrence value, iterate all sections
$referenceNode = array(
    'type' => 'section',
);

$docx->insertWordFragment($content, $referenceNode, 'before');

or use a customQuery to query by the page break tag.

Anyway, we recommend you adding headers or footers to add contents to each page, as it's the easiest solution.

Regards.