Hi Aspose team,
we have issues with document creation using Aspose.Words .NET 10.8. In some scenarios textboxes are lost when bookmark texts are replaced.
For testing purposes i’ve created a Word 2007 document and added a text and a textbox (standard template “Austere Sidebar”). Afterwards i’ve added a bookmark onto the text.
When i open this document with Aspose.Words, replace the text of the bookmark and save the document afterwards, the bookmark is lost.
The code used:
MemoryStream memoryStream = new MemoryStream(File.ReadAllBytes(filename));
Document document = new Document(memoryStream);
foreach(Bookmark bm in document.Range.Bookmarks)
bm.Text = "Replacement";
I also attach the source document and the result document. Can you please confirm this to be an Aspose issue and estimate the time until time of fix ?
Thanks and kind regards,
Thanks for your inquiry.
First of all, please note that DocumentExplorer is a very useful tool which easily enables us to see the entire document structure. You can find DocumentExplorer in the folder where you installed Aspose.Words e.g. C:\Program Files (x86)\Aspose\Aspose.Words for .NET\Demos\CSharp\DocumentExplorer\bin\DocumentExplorer.exe. Below is the DOM structure of your source document as viewed with DocumentExplorer:
In this case, the whole content enclosed in Bookmark will be replaced when you set the bookmark Text property. Also, to get better understanding, I would like to suggest you please try using the following code snippet:
Document doc = new Document(@"C:\test</font>document_source.docx");
Run run = new Run(doc);
run.Text = "New run of text in textbox";
Bookmark bm = doc.Range.Bookmarks;
Shape textBox = bm.BookmarkStart.NextSibling.NextSibling as Shape;
Please let us know if you need more information, we are always glad to help you.
thanks for the quick response. Ok, i see what you’re saying. The textbox is part of the bookmark, ok. That corresponds to the Word behaviour. When i open the bookmark dialog and double click onto the bookmark, the textbox is also getting selected. So a deletion would delete it too. So ok for that file.
Yet i have another document which i attach. When you select the bookmark in it, the textbox is not selected and hence not deleted when the bookmark is getting deleted. The document explorer still shows the shape within the bookmark though.
So what i see and whats inside the docx is not as expected to me. The issue seems to be the order of creation within Word. When i create the bookmark before the textbox was inserted it works. But when i do the same after the textbox exist, the textbox shape is part of the bookmark. It also seems to be only an issue if the bookmark and the textbox anchor are within the same paragraph.
But i dont think that you can create a bookmark in Word that contain main text and a textbox as both are part of another Interop range. If that is correct, then a bookmark can not contain a textbox. Can you confirm this ?
Thanks for your inquiry. Please note that, by Aspose.Words design, bookmark’s nodes (BookmarkStart and BookmarksEnd) are inline. This means that BookmarkStart and BookmarkEnd can be children of paragraphs only. So, when it comes to creating Bookmarks by using Aspose.Words, you can enclose any type of nodes (e.g. Runs, Shapes etc) within BookmarkStart and BookmarkEnd in a hierarchy. Also, Aspose.Words always keeps its DOM (document object model) in a hierarchical format.
Please let me know if I can be of any further assistance.
we are using Aspose.Words to open and adjust documents created with Word. We don’t create documents only with Aspose. So could this behaviour be an issue resulting from the different interpretation of bookmarks ? When Word does not support to have textbox shapes within bookmarks, why is Aspose interpret the paragraph as one and put “all” into the bookmaks, even the textbox shape. That’s what happening here, right ?!
Thank you for the additional information.
First of all, I would like to confirm here that the actions that can be performed with bookmarks using Aspose.Words are the same as the ones you can perform using Microsoft Word. You can insert a new bookmark, delete, move to a bookmark, get or set a bookmark name, get or set text enclosed in it etc.
Secondly, I think, you should confirm if MS Word supports to have textbox shapes within bookmarks by contacting Microsoft support, maybe they will be able to help to resolve this problem.
If we can help you with anything else, please feel free to ask.
Thank you for additional information. Actually, behavior of Aspose.Words is correct. Dark red textbox is within a bookmark. You can make sure by looking into the raw XML of your document. See XML below, green highlighted are bookmark start and end, yellow highlighted is your textbox. So as you can see textbox is enclosed into the bookmark:
<w:p w:rsidR="006729E9" w:rsidRPr="00430DA7" w:rsidRDefault="00E96CA6" w:rsidP="007F2D31">
<w:pStyle w:val="Heading1" />
<w:highlight w:val="yellow" />
<w:lang w:val="en-GB" />
<w:bookmarkStart w:id="0" w:name="C0982FrT000000000000383" />
<w:highlight w:val="yellow" />
<w:lang w:eastAsia="de-DE" />
<v:rect id="Rectangle 393" o:spid="_x0000_s1032" style="position:absolute;margin-left:1422.4pt;margin-top:0;width:244.8pt;height:243.45pt;z-index:251660288;visibility:visible;mso-width-percent:400;mso-position-horizontal:right;mso-position-horizontal-relative:page;mso-position-vertical:top;mso-position-vertical-relative:page;mso-width-percent:400;mso-height-rel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96TxVIHYXoVKQRS7/0xdnAAAA//8DAFBLAQItABQABgAIAAAAIQC2gziS/gAAAOEBAAAT AAAAAAAAAAAAAAAAAAAAAABbQ29udGVudF9UeXBlc10ueG1sUEsBAi0AFAAGAAgAAAAhADj9If/W AAAAlAEAAAsAAAAAAAAAAAAAAAAALwEAAF9yZWxzLy5yZWxzUEsBAi0AFAAGAAgAAAAhACk2dUX0 AgAARQYAAA4AAAAAAAAAAAAAAAAALgIAAGRycy9lMm9Eb2MueG1sUEsBAi0AFAAGAAgAAAAhAIH5 8fDdAAAABQEAAA8AAAAAAAAAAAAAAAAATgUAAGRycy9kb3ducmV2LnhtbFBLBQYAAAAABAAEAPMA AABYBgAAAAA= " o:allowincell="f" fillcolor="#943634" stroked="f">
<v:shadow type="perspective" opacity=".5" origin=",.5" offset="17pt,-52pt" matrix=",,,-1" />
<v:textbox style="mso-fit-shape-to-text:t" inset=",1in,1in,7.2pt">
<w:p w:rsidR="006729E9" w:rsidRPr="00430DA7" w:rsidRDefault="006729E9">
<w:spacing w:after="0" />
<w:color w:val="9BBB59" w:themeColor="accent3" />
<w:sz w:val="40" />
<w:szCs w:val="40" />
<w:lang w:val="en-US" />
<w10:wrap type="square" anchorx="page" anchory="page" />
<w:smartTag w:uri="http://www.accenture.com/AQDB" w:element="PlaceholderSmartTag">
<w:r w:rsidR="006729E9" w:rsidRPr="00430DA7">
<w:highlight w:val="yellow" />
<w:lang w:val="en-GB" />
<w:bookmarkEnd w:id="0" />
thanks for the further analysis. I also ran some checks with Interop and i can confirm the behaviour when replacing the bookmark is the same as in Aspose. So in the end this “issue” is more an issue of understanding from a user perspective. Because its strange to the user that the deletion of bookmarks in the first paragraph is not working like the deletion of one in the second paragraph when textbox is part of the first. But thats more a logical problem - technically its reasonable.
So i’d close the issue as works as designed.
Thanks for your support,