Replies: 10   Views: 6248
Dynamic fields with default docx template
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 isfor  · 15-02-2016 - 15:54

Hi, this is my docx template:

I'd like to replace all first page products in N products maintaing same structure and attach second page at the end.

Is it possible? How?

Posted by isfor  · 16-02-2016 - 11:44

Hi, how can i preserve header for all pages?


Posted by isfor  · 16-02-2016 - 14:35

As you saw on my attach file, i need to merge second page as last and include in it last products if it is necessary because last table with totals must appear only in last page.

If i merge it as last page it remains blank...

Can you help me?


Posted by admin  · 16-02-2016 - 15:10


After you have the DOCX merged you just need to use the importHeadersAndFooters method to add the headers to all pages of the document.

The steps are:

1. Generate a new document replacing the content of the template.

2. Merge the DOCX if needed. To do this you need the document of the previous step and the other document to merge with.

3. Import the headers to the document merged in the previous step to add the headers to all pages.

If you want to attach the second page to the end, you'll need to have this second page as a standalone DOCX to be merged. You can't split an existing document.


Posted by isfor  · 16-02-2016 - 16:17

ok thanks. Last question, i'm in web hosting and i don't know if is possible to use libreoffice or openoffice to covert docx in pdf. I tried and no output was created. Is there an alternative method?


Posted by admin  · 17-02-2016 - 07:44


You can transform very simple documents using the class. But to use the conversion plugin you need to install LibreOffice or OpenOffice on your server.


Posted by isfor  · 17-02-2016 - 08:35

Hi, if i use and function generatePDF it gives me an error: Fatal error: Class 'DOMPDF' not found

Can you help me?

Posted by isfor  · 17-02-2016 - 10:32

I included dompdf class but pdf is very different from original docx: it misses some styles and loses header and footer.

This is my code:

    require_once 'phpdocx/classes/';
    $docx2 = new TransformDoc();
    $html = $docx2->getStrXHTML();


Posted by admin  · 17-02-2016 - 13:27


You need to include the DOMPDF lib (it's included within the package in the lib folder):

require_once 'classes/';
require_once 'lib/pdf/';

$transform = new TransformDoc();

Note you need to redirect the output of this command to save the PDF:

$ php test.php > Test.pdf

or through ob_ functions of PHP.

And as explained it only returns a good output for very simple documents. The recommended approach is using the conversion plugin.