TinyMCE HTML -> DOCX

Jan 21, 2013 at 5:40 AM

Hello,

 

First, let me say that this is a great project and I'm very happy that I found it.

Now, my only problem is that I have no idea how to include inline styles (from the TinyMCE saved HTML content) and have those styles show up in my docx document.

I tried looking at the documentation, but couldn't understand how styles are used!

Thank you for your help! 

Coordinator
Jan 21, 2013 at 7:10 AM

Browse to documentation/show_raw_file.php?file=docs_styles.inc - there is an example of setting up inline styles there ($styles['inline']). Note you have to set the keys of that array to match the key-values of any inline style, e.g. if you have different font sizes in your inline style you would have to set up a different one for each font size.

Jan 21, 2013 at 7:27 AM

I assume you are talking about the following:

$styles['inline'] = 
    array(
      'text-decoration: underline' => array (
        'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE,
      ),
      'float: left' => array (
        'align' => 'left',
      ),
      'float: none' => array (
        'align' => 'center',
      ),
      'float: right' => array (
        'align' => 'right',
      ),
    );

How would I convert the following tinymce output for example?

<p><strong style="font-family: Arial, Helvetica, sans; font-size: 11px; line-height: 14px; text-align: justify;">Lorem Ipsum</strong></p>

 

Coordinator
Jan 21, 2013 at 8:43 AM

You need to work through each bit of your style and find an equivalent PHPWord style - from the PHPWord manual - PHPWord_Docs_0.6.2.docx in the phpword directory, and put these in the inline part of the styles array, e.g.:

$styles['inline'] = 
    array(
      'font-family: Arial' => array (
        'name' => 'Arial',
      ),
      'font-size: 11px' => array (
        'size' => 11,
      ),
      ...
    );

Jan 21, 2013 at 9:57 AM

Ok, I see. Thanks alot! I will report here if I have any more trouble once I look over the PHPWord Documentation.

Cheers.

Jan 22, 2013 at 4:44 AM
Edited Jan 22, 2013 at 6:10 AM

Hi Neil,

I've run into another issue. TinyMCE will output some HTML like the following ( and tags; italic and bold):

 

<em>Emphasized text</em>
<strong>Strong text</strong>
How do I translate that into Docx?

**Edit: Nevermind, I found those in the docs_style.inc example file defined under $styles['elements'].

Thanks again for your great work on this plugin!