docx4j Change the BR label to soft return when HTML is turned into Word

Source: Internet
Author: User

DOCX4J version: 3.0.1

Modify JAR Package: docx4j-importxhtml

The MAVEN configuration is:

Specific code location: \org\docx4j\convert\in\xhtml\xhtmlimporterimpl.java in Processinlineboxcontent method

Before code modification:

After the code has been modified:

private void Processinlineboxcontent (Inlinebox inlinebox, styleable s,map<string, cssvalue> cssMap) {if (                Inlinebox.gettextnode () ==null) {if (S.getelement (). Getnodename (). Equals ("BR")) { R run = context.getwmlobjectfactory (). creater ();//Getlistforrun (). GetContent (). Add (ru                n);            Run.getcontent (). Add (Context.getwmlobjectfactory (). CREATEBR ());    Element ele = S.getelement ();        if (null! = ele) {Attr attrnode = Ele.getattributenode ("style"); if (attrnode! = null && attrnode.getvalue (). Contains ("Page-break-after:always")) {br BR = Context.getwmlo        Bjectfactory (). CREATEBR ();        P p = context.getwmlobjectfactory (). Createp ();        Create object for r r r = Context.getwmlobjectfactory (). creater ();            P.getcontent (). Add (R);            Br.settype (Stbrtype.page);            R.getcontent (). Add (BR); This.contentContextStack.peek (). GetContent (). Add (P);    }//Wordmlpackage.getmaindocumentpart (). AddObject (P);                        }} else {Log.debug ("Inlinebox have no textnode, so skipping"); Todo..            A span in a span or a?                        Need to traverse?  }} else {Log.debug (Inlinebox.gettextnode (). Gettextcontent ());             Don ' t use. GetText () String thetext = Inlinebox.gettextnode (). Gettextcontent ();                        Log.debug ("Processing" + thetext);                           Parastillempty = false;        String CssClass = Getclassattribute (S.getelement ());        if (cssclass!=null) {Cssclass=cssclass.trim ();                } addrun (CssClass, Cssmap, thetext);                                     else {////Get it from the parent element eg p// Map Cssmap = StyleREference.getcascadedpropertiesmap (e);//RUN.SETRPR (//                                                                        Addrunproperties (Cssmap)); //                                    }        }}

  

docx4j Change the BR label to soft return when HTML is turned into Word

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.