We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cross Reference issue while merging multiple documents

Hi,
we are using Aspose.Words.dll version 10.5.0.0. For merging/appending multiple word document which may have cross reference for figure/table to a master word documents.
When we are merging multiple documents having cross reference in them then in the output/final merged document have updated label in caption for figure /table but cross reference source of the document is not updating or in other words output mismatch. (PFA in which problem areas are highlighted in yellow in ASPOSEOutput.docx.) In addition, cross reference has wrong references. PFA (Aspose POST.zip) for your reference. In output document all cross reference should be update like caption label and point to its right reference.
The attached folder, include the following item
· InputDoc folder contain two input document
· One master Template
· Output Folder contain Generated ASPOSE output document
Please find below code that we used for merging the word document to a master template.

string outputFile = "ASPOSEOutput.Docx";
Aspose.Words.Document MasterTemplateDoc = new Aspose.Words.Document("C:\\Aspose POST\\Master Document.docx");
string[] filePaths = Directory.GetFiles("C:\\Aspose POST\\InputDoc\\");
foreach (string file in filePaths)
{
    Aspose.Words.Document genratedDocFrag = new Aspose.Words.Document(file);
    DocumentBuilder builder = new DocumentBuilder(genratedDocFrag);
    builder.MoveToDocumentStart();
    builder.Writeln();
    builder.MoveToDocumentStart();
    builder.ParagraphFormat.ClearFormatting();
    builder.CurrentParagraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
    builder.Write("Test");
    DocumentBuilder docBuilderTemp = new DocumentBuilder(MasterTemplateDoc);
    docBuilderTemp.MoveToDocumentEnd();
    docBuilderTemp.InsertBreak(BreakType.SectionBreakNewPage);
    MasterTemplateDoc.LastSection.Body.FirstParagraph.Remove();
    foreach (Aspose.Words.Section srcSection in genratedDocFrag)
    {
        Aspose.Words.Section newSection = (Aspose.Words.Section)MasterTemplateDoc.ImportNode(srcSection, true, ImportFormatMode.UseDestinationStyles);
        MasterTemplateDoc.LastSection.AppendContent(newSection);
    }
}
MasterTemplateDoc.UpdateFields();
MasterTemplateDoc.Save(outputFileName);

So, is there any way, which solve this problem. Please let us know if any solution is possible. This problem is coming in our production server so please provide solution ASAP.
Thanks,
Samanvay

Hi
Thanks for your request. Actually, there is no problem in Aspose.Words here. The problem occurs because you merge two absolutely identical documents. As you know REF fields use bookmarks, since both of your documents are identical, bookmarks’ names are also identical. However, document cannot contain several bookmarks with the same name so duplicated bookmarks are removed and only bookmarks in the first part of document remains.
To resolve the problem, you shuld make sure your documents does nto contain duplicated bookmarks.
Best regards,

Hi
Thanks for your quick response. It helps to find out root cause of the problem.
In ASPOSE can we update bookmark so that it convert in unique when we Marge the document.
Please let me know if there is any way to solve the problem of duplicated bookmark at the time of merging the document.

Thanks
Samanvay

Hello
Thanks for your request. Please see the following link to learn how to work with bookmarks in Aspose.Words:
https://docs.aspose.com/words/java/working-with-bookmarks/
Please see the following code example:

Document doc = new Document("Bookmark.doc");
// Use the indexer of the Bookmarks collection to obtain the desired bookmark.
Bookmark bookmark = doc.Range.Bookmarks["MyBookmark"];
// Set new name of the bookmark.
bookmark.Name = "NewBookmarkName";
// Set the text of the bookmark.
bookmark.Text = "This is a new bookmarked text.";

Best regards,