admin管理员组

文章数量:1312763

When using HTML string having line breaks(br tags) and using mainDocumentPart.convertAltChunks() method of docx4j (v 8.3.11), empty lines/line breaks are more than the number of br tags which should not be the case.

HTML content:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
".dtd">

<html
 xmlns=";>
  <head>

    <title></title>
  </head>

  <body>
    <h1
     class="Heading1"
     style="font-weight: normal; line-height: 1.1; margin-top: 0.2em; margin-bottom: 0.2em;; background-color: transparent; color: rgb(64, 64, 64); font-family: Calibri; font-size: 24pt">Lorem
    Ipsum</h1>
    <br
     class="dre-paragraph"
     style="line-height: 1.3; margin-top: 0.1em; margin-bottom: 0.1em; background-color: transparent; color: rgb(64, 64, 64); font-family: Calibri; font-size: 11pt" />
    

    <h2
     class="Heading2"
     style="font-weight: normal; line-height: 1.1; margin-top: 0.2em; margin-bottom: 0.2em;; margin-left: 30px; background-color: transparent; color: rgb(64, 64, 64); font-family: Calibri; font-size: 19.5pt">Lorem
    Ipsum</h2>
    <hr
     style="border: none;border-top: 1px solid #e6e6e6;margin: 12px 0;"
     size="1"
     color="#E6E6E6"
     class="dre-horizontalRule" />
    <br
     class="dre-paragraph"
     style="line-height: 1.3; margin-top: 0.1em; margin-bottom: 0.1em; background-color: transparent; color: rgb(64, 64, 64); font-family: Calibri; font-size: 11pt" />
    

    <h3
     class="Heading3"
     style="font-weight: normal; line-height: 1.1; margin-top: 0.2em; margin-bottom: 0.2em;; background-color: transparent; color: rgb(64, 64, 64); font-family: Calibri; font-size: 15pt">Lorem
    Ipsum</h3>
    <br
     class="dre-paragraph"
     style="line-height: 1.3; margin-top: 0.1em; margin-bottom: 0.1em; background-color: transparent; color: rgb(64, 64, 64); font-family: Calibri; font-size: 11pt" />
    
  </body>
</html>

After adding above HTML content as altchunk and using mainDocumentPart.convertAltChunks() the generated docx elements(mainDocumentPart.getContent()) have few extra text elements with single space( ). Tried remove those elements as well resulting run elements having no child elements but still generated docx have more line breaks than the number of br tags which should not be the case.

How to fix this?

本文标签: