PHPWord icon indicating copy to clipboard operation
PHPWord copied to clipboard

Footer/Header in PDF

Open buchmayr opened this issue 9 years ago • 4 comments

Is it possible to render Footer and Header from Word using the PDF writer? Seems like it skips the parts created with: $section->createHeader(); $section->createFooter();


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

buchmayr avatar Jul 27 '16 14:07 buchmayr

Any news on this? Ended up inserting custom html code with a position: fixed style

zdimension avatar May 23 '21 14:05 zdimension

Any news on this? Ended up inserting custom html code with a position: fixed style

Can you show some example of your code?

vkurlenko avatar Jan 31 '23 09:01 vkurlenko

Settings::setPdfRendererName(Settings::PDF_RENDERER_DOMPDF);
Settings::setPdfRendererPath('/vendor/dompdf/dompdf');

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

$section = $phpWord->addSection();

$section->addHeader()->addImage('my-image.png');

$section->addTitle("HELLO WORLD!");
$section->addText('Lorem ipsum dolor sit amet, consetetur sadipscing elitr');

$footer = $section->addFooter();
$footer->addText('FOOTER');

$pdfWriter = IOFactory::createWriter($phpWord, 'PDF');
$pdfWriter->save('sample.pdf');

$docxWriter = IOFactory::createWriter($phpWord, 'Word2007');
$docxWriter->save('sample.docx');

The resulting .docx has header and footer but the .pdf has not. Why? I tested dompdf and mpdf.

FabianKoestring avatar Jun 07 '24 09:06 FabianKoestring

Note : https://github.com/dompdf/dompdf/wiki/Common-Use-Cases#header-and-footer

https://mpdf.github.io/headers-footers/headers-footers.html

Progi1984 avatar Aug 12 '24 18:08 Progi1984