Forum


Replies: 1   Views: 3038
Issue between word and libreoffice
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 Cedric  · 08-11-2017 - 14:05

Hi.

I'm going to explain the whole situation so, hopefully, you can help me as much as you can.

We are developing an application where users will be able to create PDF files with variables in it. To do so we decided to use PHPDocX Premium.

On the website, users have a wysiwyg editor and we save HTML in database.
When generating files, I get the stored HTML, put it in a temporary docx (temporary because we don't need to output nor save the docx, but only a PDF), and reopen it as a template.

This docx contains variables, which we replace by simple text, but they can also have special variables which represent another document that must be placed inside the first one. Since these other documents are stored the same way, I do the same process. I generate a temporary file from HTML, reopen it as a template, replace variables if there are any, save it, and I return the file's location to the first document. I then replace these special variables by external file.

Once this document has no variable left (text or file), I create it.

That's where the issue happens. 

(Currently on Window 10) When I open it with Microsoft Word, everything is fine, but when I open it with LibreOffice, the content that came from replaceVariableByExternalFile() does not appear.

Since the final application will be on a Linux Server, to generate the PDF, I will use LibreOffice, but as LibreOffice doesn't "see" the whole true content of the document, the generated PDF does not have the whole content either.

 

NB: When I opened the document with Microsoft Word, it asked me to save it to a newer version, and when I accepted, LibreOffice could find the whole content, so I guess this is due to the fact that PHPDocX saves docx as an older version, which LibreOffice is not fully compatible with ?
I tried to using transformDocxUsingMSWord() and it worked great, but since the application will end on Linux, it is not a valid solution.

My question is, do you think I can workaround this issue, and if so can you suggest how ? Besides, any way to improve the first part (before my actual problem) is welcome !

Thank you for you time and help.

Posted by admin  · 08-11-2017 - 15:14

Hello,

addExternalFile and replaceVariable methods use altChunk tags that are only supported by MS Word on Windows. You can read about this on the API method and the common problems of the conversion plugin. LibreOffice, macOS, Google Docs and many other DOCX readers don't support this tag.

There're three document formats to be inserted:

  • Replace placeholders by HTML. The best solution is using the replaceVariableByHTML method; this method generates OOXML (MS Word) tags.
  • Replace placeholders by DOCX. You can merge the DOCX using mergeDocx and then move the content after the placeholder using DOCXPath. There's a receipt about this on: Merge anywhere on the document.
  • Replace placeholders by other document formats (DOC, ODT, MHT, RTF...). Using the conversion plugin you can transform any of the supported formats to DOCX, and then use the previous approach to add and move the content.

All these approaches are compatible with all DOCX readers, so the conversion plugin based on LibreOffice will generate the PDF correctly.

Regards.