phpphpword

Can't get header text to align to top of footer in phpWord doc


I have a logo on the left and text on the right of my header. It's almost perfect but I can't get the text to appear at the very top of the page; it displays about halfway down the logo to its left.

I've played around with all the text parameters - space, indentation, before and after - to no avail. Any ideas?

My code is:

$section = $phpWord->addSection();   

$header = $section->addHeader();
$header ->addImage('logo.png',
        array(
            'width' => 200,
            'height' => 80,
          'wrappingStyle' => 'square',
    'positioning' => 'absolute',
    'posHorizontalRel' => 'margin',
    'posVerticalRel' => 'line',
        )
    );

$header->addText(
    'Company Name, Address blah blah
Blah blah blah blah blah blah blah',
    array('bold' => true),
    array(
        'space' => array('before' => 2, 'after' => 500), 
        'indentation' => array('left' => 4500, 'right' => 10)
    )
  );

Solution

  • How about just using table inside the header? With something like this (ofc with adjusting the cell sizes to something that match with your logo size):

    $section = $phpWord->addSection();   
    
    $header = $section->addHeader();
    $table = $header->addTable();
    $table->addRow();
    $table->addCell(4500)->addImage('logo.png',
            array(
                'width' => 200,
                'height' => 80,
            )
        );
    
    $table->addCell(4500)->addText(
        'Company Name, Address blah blah Blah blah blah blah blah blah blah',
        array('bold' => true)
      );