Page 1 of 1

PPr default spacing and indentation

PostPosted: Fri Apr 22, 2022 4:09 pm
by mithilesh.jha
I am converting xhtml to docx. But in document.xml below is coming :

<w:pPr>
<w:spacing w:before="269" w:after="269"/>
<w:ind w:left="120"/>
<w:jc w:val="left"/>
</w:pPr>
How can I make spacing and indentation zero .

I want like this
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
<w:ind w:left="0"/>
<w:jc w:val="left"/>
</w:pPr>
@jason

Re: PPr default spacing and indentation

PostPosted: Sat Apr 23, 2022 7:51 am
by jason
More info please. Do the values correctly reflect the input XHTML?

You can of course set the values on an individual P, p.getPpr().set....

But maybe you want to set a style instead, or the document default ppr (and delete the values on the individual paragraphs).

Re: PPr default spacing and indentation

PostPosted: Wed Apr 27, 2022 2:37 pm
by mithilesh.jha
In my xhtml , I don't have any spacing styling for P. Xhtml is like
<p><span style="font-family: Frutiger45Light; font-size: 12pt;"><strong>UBS SA</strong></span>
<span style="font-family: Frutiger45Light; font-size: 12pt;">Case Postale, CH-8098 Zurich,</span></p>

And I am passing xhtml to XHtmlImporter , so I can not change the spacing for individual P . I want default spacing and Indentation for all P's.

I tried changing PPRDefault like this in styles.xml:
<w:pPrDefault>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
<w:ind w:left="0"/>
</w:pPr>
</w:pPrDefault>

But it is not working.

Re: PPr default spacing and indentation

PostPosted: Thu Apr 28, 2022 8:31 am
by jason
If you don't set spacing in your input xhtml p, default css values will be used, and applied expressly on each w:p.

I think see com.openhtmltopdf.simple.extend.XhtmlNamespaceHandler and https://github.com/plutext/docx4j-Impor ... andler.css

So try changing that.

A value set expressly in a w:p/w:pPr overrides document default pPr, so you'd need to remove the express values to give effect to the document default pPr

Alternatively, you could try setting setParagraphFormatting(FormattingOption.CLASS_TO_STYLE_ONLY), which should result in a Word style matching a class attribute will be used, and nothing else. In other words, all direct formatting should be ignored.

Or:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
        /**
         * If the CSS white list is non-null,
         * a CSS property will only be honoured if it is on the list.
         *
         * Useful where suitable default values aren't being provided via
         * @class, or direct values are otherwise providing unwanted results.
         *
         * Using this should be a last resort.
         *
         * @param cssWhiteList the cssWhiteList to set
         */

        @Deprecated
        public static void setCssWhiteList(Set<String> cssWhiteList) {
                XHTMLImporterImpl.cssWhiteList = cssWhiteList;
        }
 
Parsed in 0.013 seconds, using GeSHi 1.0.8.4