Forum


Replies: 6   Views: 4256
Default font on lists in embedhtml (strictwordstyles)
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 larrytech  · 13-03-2015 - 16:57

We're using the embedHTML method to write HTML to a Word document. When the HTML includes a list the font defaults to Times, 10. We have the following paragraph style: // Create a paragraph style for the content. $this->document->createParagraphStyle('contentStyle', [ 'color' => '000000', 'font' => 'Trebuchet MS', 'fontSize' => 22, // Font size (each size is 0.5pt when used with EmbedHTML). 'lineSpacing' => 276, // Line space (where 240 is a line space of 1). 'jc' => 'both', 'spacingTop' => 180, // Top space (1/20 of a point). 'spacingBottom' => 180, // Bottom space (1/20 of a point). 'widowControl' => 'on' // Prevents printing the last line of a paragraph at the top of the next page. ]); And this is where we add the content. // Add the content. $this->fragments['content']->embedHTML($this->presenter->toHTML($article->content), [ 'downloadImages' => true, 'strictWordStyles' => true, 'wordStyles' => [ '

' => 'contentStyle', '

  • ' => 'contentStyle' ] ]); Is there anything we're doing wrong here?
  • Posted by admin  · 16-03-2015 - 10:19

    Hello, This script: http://pastebin.com/Jfjig00w runs perfectly. Please run it and compare it with your script. Also check Tidy is installed and enabled on your server; and that the font is available in the OS you're opening the DOCX. Regards.

    Posted by larrytech  · 16-03-2015 - 18:34

    Hello, Sorry, the problem isn't with paragraphs, but with lists. Consider the following code: http://pastebin.com/WYFL57wN This should produce both a paragraph and list in Trebuchet MS and grey, but only the paragraph has the style, and not the list (screenshot below). http://oi61.tinypic.com/am4mli.jpg Many thanks

    Posted by admin  · 17-03-2015 - 08:19

    Hello, As explained in the documentation and the examples, the createParagraphStyle method is only for text/paragraph content. If you want to use custom styles with the embedHTML method with a HTML that includes tags different like

    you need to use CSS styles or the importStyles method. Plese check the available documentation and samples. This post explain some details working with list styles: http://www.phpdocx.com/en/forum/default/topic/947 Regards.

    Posted by larrytech  · 17-03-2015 - 09:21

    Ah right, I see! The reason we tried to use paragraph styles is because in the thread you referenced: "Just to complement the information. In OOXML, lists are paragraphs with a style." so we naturally assumed that a paragraph style would work. We'll look at custom CSS and import Styles and let you know if we have any more issues!

    Posted by admin  · 17-03-2015 - 09:31

    Hello, Yes, you're right. For Word lists are paragraph, so you can style paragraphs as lists. But the embedHTML doesn't do all the process when using paragraph styles when adding lists. Regards.

    Posted by larrytech  · 17-03-2015 - 19:13

    Just for the benefit of anyone else who needs to do the same, what we did to resolve this issue: 1. Disabled strict styles on invocations to embedHTML. 2. Invoked preg_replace on the HTML output of our Markdown parser (Parsedown) to do the following: a. Replace <p> tags with <p style="font-size, text-align: ... etc b. Replace <li> tags with <li style="font-family: ...etc And that's pretty much it!