Forum


Replies: 1   Views: 2629
Chunk from replacevariablebyexternalfile is not 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 patrickmathern  · 06-03-2017 - 23:38

i'm constructing a docx file from a set of smaller templates and the .docx file looks fine.  however when i convert it to a pdf or html those sections brought in by replaceVariableByExternalFile are missing from the converted document.  if i open the .docx file in ms word and save as a new .docx file the conversion will work correctly.  has anyone else overcome this with wordfragments or merge or another mechanism?

--code snippet--

   private function replacePartial($var,$docx)    {
        $tempDir = sys_get_temp_dir();
        $tmpFile = $tempDir."/".uniqid().".docx";
        $docx->createDocx($tmpFile);
        $this->templateProcessor->replaceVariableByExternalFile([$var=> $tmpFile]);
        unlink($tmpFile);
    }

template snippet (@summary@, @analysis@ and @attachments@ are all using replacePartial above)

@summary@
@analysis@
@attachments@
body of main template @name@

--results--

the .docx file has everything included cleanly.  the .pdf file from the conversion only has the 'body of main template Joe User' portion.  if i save the .docx file using MS Word and convert again, all is perfect.

 

Posted by admin  · 07-03-2017 - 07:19

Hello,

The methods addExternalFile and replaceVariableByExternalFile use an altChunk tag that is not supported by the conversion plugin (this special tag is only supported by MS Word on Windows). Yon can read about this tag on:

http://www.phpdocx.com/documentation/conversion-plugin/common-problems-and-possible-errors

To transform HTML to DOCX and be able to transform the output document to PDF, please use embedHTML or replaceVariableByHtml methods.

If you need to merge DOCX please use the mergeDocx method:

http://www.phpdocx.com/api-documentation/docxutilities/merge-Word-documents-with-PHP

Regards.