Page 1 of 1

Word 2016 docx: outlineLvl is always null

PostPosted: Thu Jun 14, 2018 12:37 am
by rocketraman
I have a Word 2016 docx which, when parsed by docx4j 3.3.7, all the p.pPr.outlineLvl values are null. Is this a bug?

Code: Select all
  val wordMlPackage = Docx4J.load(...)
  val mainDocPart = wordMlPackage.mainDocumentPart

  // some Kotlin sugar for getting all P's from content, and then mapping each to its outlineLvl value
  val outlineLvls = mainDocPart.content.filterIsInstance<P>().map { it.pPr?.outlineLvl }
  println(outlineLvls)  // [null, null, ..., null]


UPDATE: Just tried the same doc with Aspose.Words and the outlineLvl is set correctly, though I'm trying to find reasons not to use Aspose.Words beyond the fact that it's code is obfuscated and it is expensive :-)

Re: Word 2016 docx: outlineLvl is always null

PostPosted: Thu Jun 14, 2018 10:27 am
by jason
Could you please attach sample docx?

Re: Word 2016 docx: outlineLvl is always null

PostPosted: Thu Jun 14, 2018 3:44 pm
by rocketraman
Sure, see attached.

Re: Word 2016 docx: outlineLvl is always null

PostPosted: Fri Jun 15, 2018 12:32 pm
by jason
In your sample docx, here is what a typical paragraph looks like:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
    <w:p w14:paraId="3FE8CFD8" w14:textId="441F448C" w:rsidR="00EE1C4D" w:rsidRDefault="00EE1C4D" w:rsidP="00EE1C4D">
      <w:pPr>
        <w:pStyle w:val="Heading1"/>
      </w:pPr>
      <w:r>
        <w:t>Text of Heading 1</w:t>
      </w:r>
    </w:p>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


In other words, none of the paragraphs contain outlineLvl as direct formatting.

It is however, set in the styles (ie styles part), for example:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  <w:style w:type="paragraph" w:styleId="Heading1">
    <w:name w:val="heading 1"/>
    <w:basedOn w:val="Normal"/>
    <w:next w:val="Normal"/>
    <w:link w:val="Heading1Char"/>
    <w:uiPriority w:val="9"/>
    <w:qFormat/>
    <w:rsid w:val="00EE1C4D"/>
    <w:pPr>
      <w:keepNext/>
      <w:keepLines/>
      <w:spacing w:before="240" w:after="0"/>
      <w:outlineLvl w:val="0"/>
    </w:pPr>
    <w:rPr>
      <w:rFonts w:asciiTheme="majorHAnsi" w:eastAsiaTheme="majorEastAsia" w:hAnsiTheme="majorHAnsi" w:cstheme="majorBidi"/>
      <w:color w:val="2F5496" w:themeColor="accent1" w:themeShade="BF"/>
      <w:sz w:val="32"/>
      <w:szCs w:val="32"/>
    </w:rPr>
  </w:style>
 
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


So what you need is a paragraph's effective properties. To get them, see https://github.com/plutext/docx4j/blob/ ... .java#L345

Re: Word 2016 docx: outlineLvl is always null

PostPosted: Sat Jun 16, 2018 5:20 am
by rocketraman
Thanks Jason, PropertyResolver with getEffectivePPr seems to work.