Forum


Replies: 2   Views: 2583
Adding an external docx file does not work
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 davelavinsky  · 07-03-2018 - 18:07

I tried with the simplest example here : https://www.phpdocx.com/api-documentation/word-content/insert-docx-html-rtf-mht-txt-alternative-content-into-Word-with-PHP

<?php
require_once 'config.php';
require_once CB_DIR_3DP.'phpdocx-corporate-5.5/classes/CreateDocx.inc';

$docx = new CreateDocx();

$docx->addText('aaa');
$docx->addExternalFile(array('src' => 'Text.docx'));
$docx->addText('bbb');

$docx->createDocx('example_addExternalFile');
?>

But the output file (example_addExternalFile) just contains

aaa

bbb

Posted by admin  · 07-03-2018 - 18:33

Posted by admin  · 08-03-2018 - 13:11

Hello,

Those methods are fully tested and they work&nbsp;perfectly as you can check running the included samples and opening the DOCX with MS Word 2007 or newer. But, as you can read on the documentation pages (https://www.phpdocx.com/documentation/conversion-plugin/common-problems-and-possible-errors):

altChunk tag: The addExternalFile and replaceVariableByExternalFile methods use the Word altChunk internal tag. This allows to insert external files in a Word document. This tag is MS Word supported only, so it's not compatible with the conversion plugin.

And the API method (https://www.phpdocx.com/api-documentation/word-content/insert-docx-html-rtf-mht-txt-alternative-content-into-Word-with-PHP) also explains it:

This method is not compatible with the conversion plugin: the inserted docx will not render at all in the resulting PDF, DOC, RTF, ODT or HTML document.

These methods use altChunk tags that are only supported by MS Word 2007 or newer on Windows. But they aren't supported by LibreOffice, MS Word on macOS, MS Word 2003, Google Docs and others.

If you need to add an existing DOCX to any point of another DOCX, please check the following documentation:

https://www.phpdocx.com/documentation/cookbook/merge-docx-documents-anywhere

Please note you need to use phpdocx 6.5 or newer.

Regards.