Got it, thanks!
We had to stop changing headers and footers in the docx and add them directly to pdf.
This solves our problem.
$phpdocx=new CreateDocxFromTemplate(ROOT_DIR.UPLOAD_DOCUMENTS_DIR.$document_source);
$phpdocx->addBreak(array('type'=>'page'));
$phpdocx->embedHTML($add_text);
/*
$phpdocx_numbering=new CreateDocx();
$numbering=new WordFragment($phpdocx_numbering,'defaultFooter');
$numbering->addPageNumber('numerical',array(
'textAlign'=>'right',
'bold'=>false,
'sz'=>12,
'color'=>'65a9ef',
'spacingBottom'=>0,
'spacingTop'=>0,
));
$numbering->addText($numbering_text,array(
'textAlign'=>'right',
'bold'=>false,
'sz'=>8,
'color'=>'65a9ef',
));
$phpdocx_numbering->addFooter(array('default'=>$numbering,'first'=>$numbering,'even'=>$numbering));
$phpdocx_numbering->createDocx(ROOT_DIR.UPLOAD_DOCUMENTS_DIR.$numbering_name);
$phpdocx->importHeadersAndFooters(ROOT_DIR.UPLOAD_DOCUMENTS_DIR.$numbering_name);
*/
$phpdocx->createDocx(ROOT_DIR.UPLOAD_DOCUMENTS_DIR.$temp_name);
$phpdocx->transformDocument(ROOT_DIR.UPLOAD_DOCUMENTS_DIR.$temp_name,ROOT_DIR.UPLOAD_DOCUMENTS_DIR.$pdf_name);
$pdf_util=new PdfUtilities();
$pdf_util->addBackgroundImage(ROOT_DIR.UPLOAD_DOCUMENTS_DIR.$pdf_name,ROOT_DIR.UPLOAD_DOCUMENTS_DIR.$pdf_name,ROOT_DIR.IMAGES_SETTINGS_DIR.$settings['wtm'],array('height'=>'auto','width'=>'auto','opacity'=>0.1));
class D_TCPDI extends TCPDI{
function Header(){
}
function Footer(){
$this->SetY(-10);
$this->SetFont('dejavusans','',8);
$this->SetTextColor(101,169,239);
$this->Cell(0,0,'Page '.$this->PageNo().' of '.$this->count_pages,0,0,'R');
$this->Cell(0,10,$this->numbering_text,0,0,'R');
}
}
$dtcpdi=new D_TCPDI(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,'UTF-8',false);
$dtcpdi_pages=$dtcpdi->setSourceFile(ROOT_DIR.UPLOAD_DOCUMENTS_DIR.$pdf_name);
$dtcpdi->numbering_text=$numbering_text;
$dtcpdi->count_pages=$dtcpdi_pages;
for($i=1;$i<=$dtcpdi_pages;$i++){
$dtcpdi_page=$dtcpdi->importPage($i);
$dtcpdi->AddPage();
$dtcpdi->useTemplate($dtcpdi_page);
}
$dtcpdi->Output(ROOT_DIR.UPLOAD_DOCUMENTS_DIR.$pdf_name,'F');