Forum


Replies: 4   Views: 2667
Document header is missing after docx is converted to pdf
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by ascendware  · 07-11-2019 - 14:47

Hi,

I have generated a document (docx) purely from HTML. One of the requirements is to convert this docx file to PDF. Everything is working as expected, however, the document header is missing after it was converted to PDF, while the docx file that was initially generated, the header is present.

Here is the script I used to create the document:

$phpdocx = new CreateDocx();
$headerText = new WordFragment($phpdocx, 'defaultHeader');
$headerText->embedHTML($header);
$phpdocx->addHeader(array('default' => $headerText));
$phpdocx->embedHTML($body);
$phpdocx->createDocx('/output/' . $filename);

How can I make the header appear in the converted file? Ay suggestion?

Thank you.

Posted by admin  · 07-11-2019 - 15:42

Hello,

We recommend you to use the conversion plugin based on LibreOffice, that supports headers and footers and many other content types and styles: https://www.phpdocx.com/documentation/conversion-plugin/information

If you are already using the conversion plugin based on LibreOffice, please check you are using LibreOffice 5.3 or newer. Old versions of LibreOffice may have issues working with headers and footers.

UPDATE: phpdocx 13 added support for headers and footers when using the native conversion plugin.

https://www.phpdocx.com/documentation/conversion-plugin/preparing-the-templates-for-its-conversion (Supported OOXML tags and attributes when using the native method section)

Regards.

Posted by ascendware  · 13-11-2019 - 08:05

Hi. Thank you for your response. We're currently ongoing with the troubleshooting. Follow-up question though, Is there any way we can convert an HTML directly to PDF file without converting it first to DOCX?

Posted by admin  · 13-11-2019 - 08:32

Hello,

No, there's no HTML to PDF direct conversion. This transformation needs to be done following these steps:

HTML => DOCX => PDF

Regards.

Posted by ascendware  · 13-11-2019 - 16:19

Hi, thank you for that quick reply. We got the PDF conversion working now with the header and footer displayed. We used LibreOffice as the conversion plugin.

Thanks a lot!