Hi there,
While merging documents we are seeing that -
Case 1:
doclet0 contains Sales
doclet1 contains Sales
then merged doc would have Sales and Sales_0.
That is the behavior we expected but consider the case 2,
Case 2:
doclet0 contains Sales
doclet1 contains sales
then merged doc would have Sales only and sales of doclet2 is totally missed while merging.
We expected merged document would have two bookmarks ‘Sales’ and ‘sales’. Even bookmark is not in XMLs.
Thanks.
Hi Praneeth,
Thanks for your inquiry. Please note that Aspose.Words tries to mimic
the same behavior as MS Word do. MS Word allows only unique names for
bookmarks. If you change the name of a bookmark to a name that already
exists in the document, no error will be given and only the first
bookmark will be stored when you save the document. When you add a
cloned Paragraph into the document, its bookmark will not be stored due
to same name.
It would be great if you please share following detail for investigation purposes.
- Please attach your input Word documents.
- Please
create a standalone/runnable simple Java application that demonstrates the code (Aspose.Words code) you used to generate
your output document - Please attach the output Word file that shows the undesired behavior.
- Please
attach your target Word document showing the desired behavior. You can
use Microsoft Word to create your target Word document. I will
investigate as to how you are expecting your final document be generated
like.
us we’ll start our investigation into your issue.
Thanks for looking into this.
Hi Tahir,
We are seeing the same behavior (renaming of bookmarks) with newer version of Aspose.
Attaching 3 input docs:
doc3.docx: 3 bookmarks {Acquisitions, Expenditure, Sales}
doc4.docx: 3 bookmarks {Acquisitions, Expenditure, Sales}
doc6.docx: 3 bookmarks {asposeisaspose, expenditure, sales, acquisitions}
and the output document generated via following code -
UnusualMerge_doc3_4_6.docx, having bookmarks as -
{Acquisitions, Expenditure, Sales, Acquisitions_0, Expenditure_0, Sales_0,
asposeisaspose} and two unknown hidden bookmarks are created during the process - {_GoBack_0, _GoBack_1}.
Document doc3 = new Document(“doc3.docx”);
Document doc4 = new Document(“doc4.docx”);
Document doc6 = new Document(“doc6.docx”);
doc3.appendDocument(doc4, ImportFormatMode.KEEP_SOURCE_FORMATTING);
doc3.appendDocument(doc6, ImportFormatMode.KEEP_SOURCE_FORMATTING);
So, As we said the Aspose is doing bookmarks renaming while merging the documents and more seriously missing few bookmarks if case is differing in subsequent documents. The one more new issue, we saw now - is the creation of hidden bookmarks in the output document.
Thanks for looking.
Hi Praneeth,
Thanks for sharing the detail.
I have tested the scenario and have managed to reproduce the same issues at my side. For the sake of correction, I have logged these problems in our issue tracking system as follow:
WORDSNET-10540 : Document.AppendDocument rename the bookmarks
WORDSNET-10541 : Hidden bookmark are created after joining documents
I have linked this forum thread to the same issues and you will be notified via this forum thread once these issues are resolved. We apologize for your inconvenience.
Thanks Tahir for looking into this.
As the few bookmarks in different cases {expenditure, sales, acquisitions}, in the subsequent doc6.docx part, are also missed while appending the documents, could you please look into that or log it as a issue?
Hi Praneeth,
Thanks for your inquiry. Could you please share some detail about missing bookmarks issue? I have not found this issue in final output document. The bookmarks asposeisaspose, expenditure, sales and acquisitions exist in output document. I have attached the output document with this post for your kind reference.
Hi Tahir,
Yes that’s correct but the bookmarks present are not the ones belonging to doc6.docx, i.e; {expenditure, sales, acquisitions}, these are {Expenditure, Sales, Acquisitions} which are all exists in doc3.docx part in the output document.
I assumed that since Aspose is renaming the bookmarks while merging, so 10 bookmarks should be present in any form, i.e;{Acquisitions, Expenditure, Sales, Acquisitions_0, Expenditure_0, Sales_0, asposeisaspose, expenditure, sales, acquisitions}
OR
{Acquisitions, Expenditure, Sales, Acquisitions_0, Expenditure_0, Sales_0,
asposeisaspose, expenditure_1, sales_1, acquisitions_1}, but clearly only 7 are present.
This is the reason for our reasoning behind 3 bookmarks being missed. Hope I’m making sense.
Thanks.
PS: Our main issue is not with renaming of bookmarks (we actually desire the renaming functionality, at least for now) but bookmarks being missed if are in different case in subsequent documents and the hidden bookmarks being created, while appending.
Hi Praneeth,
is by MS WORD design that a Word document must have unique names for
bookmarks. You can not insert two bookmarks with the same names. I
think, in your case, you can simply try renaming bookmarks before appending documents.
We will update you via this forum thread once these issues are resolved. We apologize for your inconvenience.
Hi Tahir,
That’s fine, I understand your point. My point is behavior should be the same in all cases which is not the case.
In one case Aspose is renaming the bookmarks and in another case it is missing certain specific bookmarks which are in different cases. So, our point is something is wrong at the time of appending or scanning the bookmarks, as the behavior is not consistent.
Thanks for looking into this.
Hi Praneeth,
The issues you have found earlier (filed as WORDSNET-10540;WORDSNET-10541) have been fixed in this .NET update and this Java update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.
Hello.
We are planning to upgrade Aspose.Words library and while evaluating version 23.9 we see one of the two issues mentioned in this thread is still not working as expected.
Attached is the zip file containing the following:
- doc3.docx, doc4.docx, doc6.docx - three input doclet files having bookmarks with same names
- OutputDoc_23.9.docx - generated output document that illustrates the issue
- TestAddBookmarksThreeDoclets.java - small unit-test having description of the input and expected output
Expected behaviour would still be as noted in the thread: {Acquisitions, Expenditure, Sales, Acquisitions_0, Expenditure_0, Sales_0,
asposeisaspose, expenditure_1, sales_1, acquisitions_1} . But the links from the first doclet (Doc3.docx) are missing in the output.
This was tested in both Win11 OS as well as Linux 7.4.
Please let us know if you need additional details.
Thank you,
Yan
TestAddBookmarksThreeDoclets.zip (38.2 KB)
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-26114
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
The problem occurs because there are bookmarks with the same name, but in different case. You can workaround the problem using the following code:
Document doc3 = new Document("C:\\Temp\\doc3.docx");
Document doc4 = new Document("C:\\Temp\\doc4.docx");
Document doc6 = new Document("C:\\Temp\\doc6.docx");
fixBookmarkNames(doc3);
fixBookmarkNames(doc4);
fixBookmarkNames(doc6);
doc3.appendDocument(doc4, ImportFormatMode.KEEP_SOURCE_FORMATTING);
doc3.appendDocument(doc6, ImportFormatMode.KEEP_SOURCE_FORMATTING);
doc3.save("C:\\Temp\\out.docx");
private static void fixBookmarkNames(Document doc) throws Exception
{
for(Bookmark bk : doc.getRange().getBookmarks())
bk.setName(bk.getName().toLowerCase());
}
The issues you have found earlier (filed as WORDSNET-26114) have been fixed in this Aspose.Words for Java 24.1 update.