Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Dec 15, 2022 9:29 pm

Hello.
When trying to appendHtml text to existing document, the text is cut before use of <a> or <br> tag
If htmlString to be appended to paragraph is as follows,
Code: Select all
Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br>
Curabitur hendrerit. Phasellus (<a target=\"_blank\" href=\"https://www.e-iceblue.com\">www.e-iceblue.com</a>)
Etiam odio pretium molestie. Vestibulum


appended result is cut before <br> tag:
Code: Select all
Lorem ipsum dolor sit amet, consectetur adipiscing elit.


If htmlString to be appended to paragraph is as follows,
Code: Select all
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Curabitur hendrerit. Phasellus (<a target=\"_blank\" href=\"https://www.e-iceblue.com\">www.e-iceblue.com</a>)
Etiam odio pretium molestie. Vestibulum


appended result is cut before <a> tag:
Code: Select all
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur hendrerit. Phasellus (


Hotfix to this behaviour is to add at the end of appended htmlString empty <p></p> tag.
if htmlString to be appended to paragraph is as follows,
Code: Select all
Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br>
Curabitur hendrerit. Phasellus (<a target=\"_blank\" href=\"https://www.e-iceblue.com\">www.e-iceblue.com</a>)
Etiam odio pretium molestie. Vestibulum
<p></p>


appended result is as expected:
Code: Select all
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur hendrerit. Phasellus (www.e-iceblue.com) Etiam odio pretium molestie. Vestibulum


Code used to append htmlString to existing document is:
Code: Select all
Section tempSection = document.addSection();
tempSection.addParagraph().appendHTML(htmlString);
TextBodySelection selection = new TextBodySelection(tempSection.getBody(), 0, tempSection.getBody().getChildObjects().getCount() - 1, 0, 0);

TextBodyPart bodyPart = new TextBodyPart(selection);

BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
bookmarkNavigator.moveToBookmark(bookmarkName);
bookmarkNavigator.replaceBookmarkContent(bodyPart);

document.getSections().remove(tempSection);

matus.vandak
 
Posts: 18
Joined: Fri Sep 02, 2022 10:00 pm

Fri Dec 16, 2022 10:01 am

Hello,

Thanks for your inquiry.
After investigation, I reproduced your issue and logged it into our bug tracking system with the ticket number SPIREDOC-8900. Our development team will investigate and fix it. Once it is resolved, I will inform you in time. Sorry for the inconvenience caused.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Mon Jul 24, 2023 2:19 am

Hello,

Thanks for your patiently waiting.
For the issue with the number SPIREDOC-8900, I have some information to inform you:
To achieve the effect you want, you need modify your code, please change the pItemEndIndex paramter from 0 to subtract one from the count of the child object of last document object in temp section, such as the following screenshot.
test.png

If the value of pItemEndIndex is 0, that mean the selection object only contain the first child object of last document object in temp section.
1) When there are ‘</br>’ in html code, the first child object is a TextRange, and the value of it is “Lorem ipsum dolor sit amet, consectetur adipiscing elit.”, which is a string before ‘</br>’.
2) When there are not ‘</br>’ in html code, the first child object is the string before ‘<a>’.
3) When there are ‘<p>’ in the html code, there will be add a blank paragraph in temp section, and the first child object is the first child object of the blank paragraph. Therefore, the result word will contain all string of html code.
To avoid this, so you need put the last child object of the last document object in temp section to selection.

Hope this can help you. And if you have any issues, just feel free to contact us.


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.Doc