Forum


Replies: 24   Views: 10391
<li> with strictwordstyles = true
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 shroom  · 03-12-2015 - 17:13

Say I have a simple HTML <ul> list:

$html .= '<ul><li>One</li><li>Two</li><li>Three</li></ul>';

When embedHTML() is used with strictWordStyles = false, the list renders fine.  There is no extra space between the listitems.

When strictWordStyles = true, there is an extra space between the listitems.

What do I need to do to get rid of the extra space?

Thanks.


 

Posted by admin  · 04-12-2015 - 08:52

Hello,

What license are you using?

Regards.

Posted by shroom  · 05-12-2015 - 18:39

None yet.  We will probably be buying a professional license next week.

Posted by admin  · 08-12-2015 - 07:41

Hello,

Sorry but the free trial doesn't include any support but for general questions and minor doubts.

Regards.

Posted by shroom  · 11-12-2015 - 15:26

Now that we have a Pro license, can I please get an answer to my question?

Thanks.

Posted by shroom  · 14-12-2015 - 20:31

Thanks for responding.

>>So to change the default list behaviour, you need to set a custom list style in wordStyles parameter.

Note that I am not using a styled <ul>.  As I mentioned in the first post in this thread, even a very basic unstyled <ul> displays differently depending on whether strictWordStyles is true or false.

If I do need to define a custom list style, which array option key for createListStyle() controls whether there is an extra blank line after each list item?  The keys listed in the documentation are type, font, format, hanging, and left.  In reading their descriptions, none of them seem to control whether there is a blank line following each list item.

Thanks

Posted by admin  · 15-12-2015 - 09:08

Hello,

Lists in Word are paragraphs and have their own styles, even if don't they have one explicitly. To do what you need we recommend you to use a custom style when setting strictWordStyles as true.

Regards.

Posted by shroom  · 15-12-2015 - 15:12

>>To do what you need we recommend you to use a custom style when setting strictWordStyles as true.

Again, what style would I need to use?  How should I set it up?  None of the option keys for custom list styles seem to have anything to do with whether or not there is an extra line after each <li>

Thanks.

Posted by admin  · 15-12-2015 - 16:57

Hello,

You need to use createListStyle method (http://www.phpdocx.com/api-documentation/layout-and-general/create-Word-custom-list-style-with-PHP) or a DOCX with the needed style and import it using importStyles method (http://www.phpdocx.com/api-documentation/layout-and-general/import-styles-from-a-Word-document-with-PHP).

There isn't a preset style for all kind of lists you can do with Word. If you need a special list style you need to create/import to use it in the DOCX.

The API documentation pages explain how to do that, but we're writing a new sample to explain how to do exactly what you need.

Regards.

Posted by shroom  · 15-12-2015 - 19:41

I am familiar with importStyles().  I don't think I need a special createListStyle.  It's just a simple, basic <ul> that phpdocx renders differently depending on whether strictWordStyles is true or false.

Here is a basic <ul>.  The html is: "<ul><li>one</li><li>two</li><li>three</li></ul>"

  • one
  • two
  • three

When strictWordStyles=false, phpdocx generates the list as it should.  It looks exactly as above.  When strictWordStyles=true, the list is generated like this:

  • one
     
  • two
     
  • three

An extra line is inserted between the list items.  If I must create a special list style using createListStyle() to get phpdocx to not insert the extra line, what would it be?  Again, I cannot see where any of the option keys have anything to do with inserting an extra line between list items.

Thanks

Posted by admin  · 16-12-2015 - 07:21

Hello,

You don't see any option to avoid or insert an extra line between list items because it doesn't exist. You need do it through list styles, this is creating or importing the list style.

Regards.

Posted by shroom  · 16-12-2015 - 13:21

I understand that I apparently must create a custom list style in order to have phpdocx generate a regular, normal, <ul> when strictWordStyles = true.  I understand how to apply the custom list style to the <ul>'s in my html.  What, specifically, is the custom list style I must create?  How do I create a custom list style indicating I do not want the extra blank line between the list items?  I have read the docs on creating custom list styles and could find nothing about how to indicate that I do not want the extra line between list items.

Thanks.

Posted by admin  · 16-12-2015 - 16:25

Hello,

We're writing an example to show how to do it.

Regards.

Posted by shroom  · 16-12-2015 - 22:53

Thank you.

Posted by admin  · 17-12-2015 - 09:17

Hello,

As you can see if you open the DOCX, there's no extra line between list items but the default Word spacing when using the phpdocx base template. This default style applies because you set the strictWordStyles as true.

To solve it, the easiest approach is to open the default template and set the default spacing as 0 to the paragraph style applied to the list (Normal style as usual).

Doing this simple step we have checked it works perfectly.

Regards.

Posted by shroom  · 17-12-2015 - 15:24

>>To solve it, the easiest approach is to open the default template and set the default spacing as 0 to the paragraph style applied to the list (Normal style as usual).

This is not an acceptable solution.  I do not want to remove the extra space for normal paragraphs (the Normal style), only for lists.  Also, when I open the created docx in MSWord and add another list, there is no extra space between the list items.  Likewise, if I select the list brought in by phpdocx, remove the <list> formatting, and reapply the <list> formatting, there is no extra space between the items.  Something is happening in phpdocx when it renders the <ul>.

So apparently I do need a custom list style in order to render <ul>s without the extra line.  I would like to know what that custom style should be.

Thanks.

Posted by admin  · 17-12-2015 - 15:33

Hello,

Then you need to set the strictWordStyles option as false for that chunk of text, there's no other approach to do it in the current version of phpdocx when you import a HTML. As list as paragrahs internally, to create a custom style you just need to remove the top and bottom margins in your template.

This is a quick patch to add support when strictWordStyles is true:

Edit the file HTML2WordML.inc and in line 1949 (after the 'if (!$this->strictWordStyles) {') add this:

 else {
  $stringListPr .= $this->pPrSpacing($properties);
}

Now you can set a custom spacing, for example:

$html .= '<ul><li style="margin-bottom: 10px;margin-top: 10px;">one</li><li style="margin-bottom: 0px;margin-top: 0px;">two</li><li style="margin-bottom: 0px;margin-top: 0px;">three</li></ul>';

Setting the 0px to top and bottom you can remove the spacing between items. You may use inline styles or a CSS stylesheet.

Regards.

Posted by shroom  · 17-12-2015 - 17:09

This is a quick patch to add support when strictWordStyles is true:

Edit the file HTML2WordML.inc and in line 1949 (after the 'if (!$this->strictWordStyles) {') add this:

 else {
  $stringListPr .= $this->pPrSpacing($properties);
}

This got me very close to what I was after, thanks!  I did not need to style the <li>s at all.  The only thing I had to do in my inbound $html was str_replace('</ul>', '</ul><br />', $html); to provide an extra line after the last <li> before the next paragraph.  It's not perfect, but very close.

Which line in HTML2WordML.inc would I need to modify to allow it to read inline styles for the <ul> itself?  Something like <ul style="margin-bottom:1em">.  Is that possible?  If this can be done, I think it -would- be perfect.

Thanks again.

Posted by shroom  · 17-12-2015 - 19:42

I figured it out.  I added the following code to generatePPr()  around line 1592 (for some reason, my file line numbers are slightly different that yours..)

else{
    $stringPPr .= $this->pPrSpacing($properties);
 }

It works, and I have not noticed any ill effects.  Now <ul>s and <ol>s are rendered perfectly, even with strictWordStyles = true.

Thanks for the help.