Forum


Replies: 1   Views: 657
Trying to add html forms and other tags to docx before converting to html
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 rstoeber  · 26-12-2020 - 17:22

Quick question: Is it possible to replace a tag in a docx file with an HTML form, and then transform that docx to HTML containing a functional form?

Background:

Our users design/create their own docx files containing a variety of "tags" for addresses, phones, names, prices, etc. The tags are then replaced at runtime with appropriate data using replaceVariableByText and replaceTableVariable. After replacing the variables (tags) we add photos (if the user has included any) to the end of the document using addImage and then output a final docx file. We also use TransformDocAdvLibreOffice to generate a PDF and save that. This all works perfectly.

Next we are trying to add a signature feature that can be used by anyone, in any web browser. I thought it would be a simple matter to add some html-specific content (an HTML form contacting a canvas element) and then transform our finished docx file to HTML using TransformDocAdvHTML.

I tried using both replaceVariableByText and replaceVariableByHTML to insert the HTML form where the user needs it placed. Both of those options generate a lot of formatting around HTML tags so the form doesn't actually work.

Here is a simple example of the final result that I am trying to acheive. Look near the bottom of that page for a place you can draw your signature. 

https://staging.workglue.net/COVID-19/Estimate-sample-2020.html

After many tests I'm not sure we can reliably and accurate reproduce any random docx file as HTML anyway. So, this may be a dead end, and we will have to try something completely different. But, I'm still curious about whether it's possible to use phpdocx to insert functional HTML into a docx file and then output HTML.

Any ideas appreciated.

 

Posted by admin  · 26-12-2020 - 19:53

Hello,

The replaceVariableByText method doesn't transform HTML, this method replaces a placeholder by a new text (plaing strings).

If you want to replace a placeholder by HTML you need to use replaceVariableByHTML. But please note that this method supports many HTML tags and CSS styles but not all, for example HTML canvas tag isn't supported when transforming HTML. We recommend you to read the following pages that detail all suported contents and styles when transforming HTML:

Instead of a canvas you could add an input field or other MS Word content type to generate a box when transforming HTML. Also please note that some HTML tags and CSS styles don't have a MS Word equivalent.

Regards.