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.

Wed Mar 22, 2023 8:57 am

Hello
using spire.doc for Java, version 11.3 I found that when trying to appendHtml text in case of first paragraph, style "display: none" is not applied and the text inside paragraph is visible.
Then in next usage the style is really applied and the paragraph text is not visible.

Display_none.png

Inserted html text:
Code: Select all
<p style="display: none">Text that should not be visible</p>
<p>Text that should be visible<p>
<p style="display: none">Text that should not be visible and is not visible</p>


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);

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

Wed Mar 22, 2023 9:58 am

Hi,

Thanks for your inquiry.
I did a test with your code but I didn't reproduce your issue, the style "display: none" worked.
Here is my full code, and I attached my input file and output file.
Code: Select all
 Document document = new Document();
        document.loadFromFile("C:\\Users\\Administrator\\Desktop\\test.docx");
        //add a section.
        Section sec = document.addSection();

        String htmlString ="<p style=\"display: none\">Text that should not be visible</p>\n" +
                "<p>Text that should be visible<p>\n" +
                "<p style=\"display: none\">Text that should not be visible and is not visible</p>";

        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("test");
        bookmarkNavigator.replaceBookmarkContent(bodyPart);
        //save to a Word file.
        document.saveToFile("1.docx", FileFormat.Docx);


Could you please share your files to help us reproduce your issue? You could attach them here or send them to us via email (support@e-iceblue.com).
Thanks for your help in advance.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Wed Mar 22, 2023 10:57 am

Hello, thank you for your answer.

I am saving the document as PDF file. I did not mentioned it, but it seems that it is the difference.

I can confirm, that save to DOCX file works correctly, but save to PDF not.

Code: Select all
document.saveToFile("1.pdf", FileFormat.PDF);


pdf_vs_docx.png

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

Thu Mar 23, 2023 8:32 am

Hi,

Thanks for your sharing further information.

I was able to replicate the issue you mentioned when saving to a PDF document. We apologize for any inconvenience caused. I have logged this issue into our issue tracking system with the number SPIREDOC-9201. I will notify you once the issue has been resolved.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc