Hi Team,
I am working on merging multiple Word documents.
I have set the section start to Aspose.Words.SectionStart.Continuous, but the sections are still not appearing as continuous.
Could you please help me resolve this issue in the code?
Code Snippet :
List<string> documentPathList = new List<string>(); //here is the path of all documents
Aspose.Words.Document mainDoc = null;
for (int i = 0; i < documentPathList.Count; i++)
{
var bytes = File.ReadAllBytes(documentPathList[i]);
Aspose.Words.Document doc = new Aspose.Words.Document(new MemoryStream(bytes));
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
Aspose.Words.Bookmark bookmarkStart = doc.Range.Bookmarks.Where(a => a.Name.Contains("Section") && a.Name.Contains("Start")).FirstOrDefault();
Aspose.Words.Bookmark bookmarkEnd = doc.Range.Bookmarks.Where(a => a.Name.Contains("Section") && a.Name.Contains("End")).FirstOrDefault();
if (bookmarkStart != null)
{
bookmarkStart.Remove();
}
if (bookmarkEnd != null)
{
bookmarkEnd.Remove();
}
builder.MoveToDocumentStart();
builder.MoveToDocumentEnd();
Aspose.Words.SectionStart sectionStart = Aspose.Words.SectionStart.Continuous;
doc.FirstSection.PageSetup.SectionStart = sectionStart;
if (mainDoc == null)
mainDoc = doc;
else
{
if (doc.LastSection.Body.LastChild.NodeType == Aspose.Words.NodeType.Paragraph)
{
var para = new Aspose.Words.Paragraph(doc);
doc.LastSection.Body.AppendChild(para);
}
mainDoc.AppendDocument(doc, Aspose.Words.ImportFormatMode.KeepSourceFormatting);
}
}
mainDoc.Cleanup();
mainDoc.WebExtensionTaskPanes.Clear();
mainDoc.RemoveExternalSchemaReferences();
mainDoc.RemoveMacros();
mainDoc.CompatibilityOptions.OptimizeFor(Aspose.Words.Settings.MsWordVersion.Word2019);
mainDoc.Save(@"Output.docx", Aspose.Words.SaveFormat.Docx);
Output :
Output.docx (31.1 KB)
Documents :
Note 5. REVENUE_Sample.docx (14.1 KB)
Note 4. PROPERTY AND EQUIPMENT_Sample.docx (14.9 KB)
Note 3. INVENTORY_Sample.docx (14.0 KB)
@AlpeshChaudhariDev
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-28336
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.
Is there any update here ?
@AlpeshChaudhariDev Unfortunately, the issue is not resolved yet. We will keep you updated and let you know once it is resolved or we have more information for you.
Hi @alexey.noskov ,
Even I am also facing the same issue.
this was working fine till version 25.5. In further releases the same is not working.
@Coder365 Yes, the issue has been introduced as a side effect of WORDSNET-28243 fix, which was added in 25.6 version of Aspose.Words. A draft of the fix is already implemented. if everything goes smoothly, the fix will be included into the next 26.1 version of Aspose.Words.
Just paid/renewed to the latest, 25.12.0 but have the same problem. Was running fine in the old versions back to 2020, 2018 etc. Looking for fix for this issue before we can release to this upgrade. Thanks
@sagerion The fix will be included into the next 26.1 version of Aspose.Words. it will be required to use code like the following to prevent appending document with new page section break:
Document dstDoc = new Document();
Document srcDoc = new Document();
srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;
ImportFormatOptions options = new ImportFormatOptions { AppendDocumentWithNewPage = false };
dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting, options);
1 Like
The issues you have found earlier (filed as WORDSNET-28336) have been fixed in this Aspose.Words for .NET 26.1 update also available on NuGet.
97% there, still some documents don’t append continuous even with that code. They had been working the same since 2016 across multiple versions of Aspose until this latest round of updates. Example is the first document has 2 pages, the second page only has say one line of paragraph in it, the appending 2nd document doesn’t append continuous, it shows up as a new page. Same code that is above works most of the time but not always.
@sagerion Could you please attach the problematic input and output documents here for testing? We will check the and provide you more information.
I’ll work on that next, have to pare down a simple example.
1 Like
My bad, I had one more AppendDocument call that was not using the new code - fixed.
1 Like