Forum


Replies: 3   Views: 1525
Gdocs is not showing headings at all
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 admin  · 25-11-2020 - 11:04

Hello,

The heading tags are being added correctly to the DOCX using w:outlineLvl tags:

<w:outlineLvl w:val="2"/>

as you can check if you open the DOCX with MS Word or LibreOffice and update the TOC. The problem is that Google Docs has many restrictions and it doesn't read the OOXML standard (used by DOCX documents) correctly: charts, complex lists, absolute positions, complex table styles, outline level tags and others.

UPDATE: Working with headings using PHP methods and HTML contents

To set a heading tag compatible with Google Docs (and also MS Word and LibreOffice), you need to use a heading content as you are using now (using h1, h2 tags... with HTML Standard or the phpdocx_heading tag with HTML Extended) and also apply a preset custom style supported by Google Docs (Heading1 with exact name heading 1, Heading2 with the exact name heading 2...). As you are using a template (and also it contains Heading1, Heading2... tags), you can use the existing styles when importing HTML:

$html = '
  <p>Content</p>
  <h1 style="color: #b70000">A heading1 content</h1>
  <h2 style="color: #b70000">A heading2 content</h2>
';
$docx->embedHTML($html, array('wordStyles' => array('<h1>' => 'Heading1', '<h2>' => 'Heading2')));

Google Docs, and other DOCX readers, has some limitations when reading DOCX contents, although phpdocx includes option to get the maximum compatibility. Instead of supporting w:outlineLvl tag as OOXML standard details, Google Docs uses fixed paragraph style names (if you generate other style name with other name but the same properties it won't work as TOC content).

Regards.