Setting font to unhidden in bookmark range

Hello,

I am trying to set the font in a bookmark range to not hidden. But I cannot seem to update the range so it is actually not hidden. How do I accomplish this? Here is my code:

builder.MoveToBookmark(bm.bookmarkName);
try
{
    Word.Bookmark bookmarktext = WordDoc.Range.Bookmarks[bm.bookmarkName];

    builder.Font.Hidden = false;
}

@david.irons,

Please ZIP and attach the following resources here for testing:

  • Your simplified input Word document
  • Aspose.Words 19.4 generated output document showing the undesired behavior (if any)
  • Your expected document showing the correct behavior. You can create expected document by using MS Word.

As soon as you get these pieces of information ready, we will start further investigation into your issue and provide you code to achieve the same by using Aspose.Words. Thanks for your cooperation.

The zip file is uploaded. hidden.doc has a range of text hidden. unhidden.doc is SUPPOSED to have the same range unhidden, but it does not. it should be this.doc is what it should look like.

@david.irons,

I am afraid, we do not see any attachments in this thread.

You can also upload the ZIP file to Dropbox and share the Download link here for testing.

When I upload the zip, it says it is successful. Is there another way to upload? My employer blocks access to dropbox.

@david.irons,

Please use any other file hosting/storage service e.g. ‘OneDrive’, ‘Google Drive’ and upload the required resources their. Thanks for your cooperation.

Please try this from Onedrive: https://1drv.ms/f/s!AugT_LGUxGBBbXLJWN4N0saCek4

@david.irons,

Please use the following code to change font properties of Run nodes contained inside a Bookmark:

Document doc = new Document("E:\\Integrated_81_Replace_CS.doc");

Bookmark bm = doc.Range.Bookmarks["BulletBM"];

Node currentNode = bm.BookmarkStart;
while (currentNode != null)
{
    currentNode = currentNode.NextPreOrder(currentNode.Document);

    if (currentNode.NodeType == NodeType.BookmarkEnd)
        if (((BookmarkEnd)currentNode).Name == bm.BookmarkStart.Name)
            break;

    if (currentNode.NodeType == NodeType.Run)
    {
        //modify font properties
        Run run = (Run) currentNode;
        run.Font.Hidden = false;
        run.Font.Color = Color.Red;
    }
}

doc.Save("E:\\19.4.docx");

Hope, this helps.

That does unhide the text. However, the formatting and styles get messed up. If you click on the show/hide control in Word on the resultant doc, you can see what I mean. Is there a way to fix that?

@david.irons,

You also need to set the font formatting of paragraph break character. Please use the following modified code to get the desired output

Document doc = new Document(MyDir + "Integrated_81_Replace_CS.doc");

Bookmark bm = doc.Range.Bookmarks["BulletBM"];

Node currentNode = bm.BookmarkStart;
                
//modify font properties
Paragraph para = (Paragraph)bm.BookmarkStart.ParentNode;
para.ParagraphBreakFont.Hidden = false;

while (currentNode != null)
{
    currentNode = currentNode.NextPreOrder(currentNode.Document);

    if (currentNode.NodeType == NodeType.BookmarkEnd)
        if (((BookmarkEnd)currentNode).Name == bm.BookmarkStart.Name)
            break;

    if (currentNode.NodeType == NodeType.Paragraph)
    {
        //modify font properties
        Paragraph paragraph = (Paragraph)currentNode;
        paragraph.ParagraphBreakFont.Hidden = false;
    }

    if (currentNode.NodeType == NodeType.Run)
    {
        //modify font properties
        Run run = (Run)currentNode;
        run.Font.Hidden = false;
        run.Font.Color = Color.Red;
    }
                     
}

doc.Save(MyDir + "out.docx");

That all works great!! Thank you so much!!