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.