Forum


Replies: 10   Views: 7090
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: http://gestionale.ebpmi.it/phpdocx/test.docx

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?

Thanks

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?

Thanks

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

Hello,

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.

Regards.

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?

Thanks

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

Hello,

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

Regards.

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

Hi, if i use TransformDoc.inc 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/TransformDoc.inc';
    $docx2 = new TransformDoc();
    $docx2->setStrFile('phpdocx/parte1d.docx');
    $docx2->generateXHTML();
    $html = $docx2->getStrXHTML();
    $docx2->generatePDF('phpdocx/parte1d.pdf');

 

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

Hello,

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

require_once 'classes/TransformDoc.inc';
require_once 'lib/pdf/dompdf_config.inc.php';

$transform = new TransformDoc();
$transform->setstrFile('Text.docx');
$transform->generatePDF();

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.

Regards.