Search code examples
phpword

I can't have both personnalized footer and header on same page


I'm creating a docx file that will be open with LibreOffice and I have some trouble with displaying both header and Footer on the same page

When I add both Header and Footer to display, only one show on the first page then I got an empty page and then my page context with both header and footer on a second page. If I put the footer before the header it will be the footer on each page and the same if I put the header before the footer

$phpWord = new \PhpOffice\PhpWord\PhpWord();

$section = $phpWord->createSection();
$footer = $section->createFooter(array('align'=>'center'));
$footer->addPreserveText('POSTAL ADRESS some text ');
$footer->addPreserveText('STANDARD - tel:  - fax: ');
$footer->addPreserveText("Page {PAGE} of {NUMPAGES}.");


$section = $phpWord->createSection();
$header = $section->createHeader();
$header->addImage(
    'image.png',
    array(
        'width' => 150,
        'height'=> 75,
        'marginTop'=>500,
        'marginLeft'=>400000,
        'align'=>'center',

    )
);

I expect to have a single page with both header and footer displayed.


Solution

  • I just deleted the section creation under the footer creation and it solved my problem, my toughts is that they "share" the same type of section.