Indeed I had not this line but when I added it, it didn't change the problem.
In the pdf, the beginning of the second document of the loop is sticked to the end of the previous one whereas in the Word it starts on the next page.
Document finalDoc = new Document();
for (int i = 0; i < 10; i++)
{
Document doc = new Document();
doc.LoadFromFile("..\\..\\template_spire.docx");
foreach (Section s in doc.Sections)
{
Table t = new Table(doc);
TableRow r = t.AddRow();
TableCell c = r.AddCell();
t.TableFormat.LayoutType = LayoutType.Fixed;
t.PreferredWidth = new PreferredWidth(WidthType.Percentage, 100);
int breakCount = 0;
while (s.Body.ChildObjects.Count - breakCount > 0)
{
DocumentObject obj = s.Body.ChildObjects[0];
if (obj is Paragraph)
{
Paragraph paraChild = obj as Paragraph;
Paragraph para = obj.Clone() as Paragraph;
paraChild.ChildObjects.Clear();
int breakIndex = -1;
foreach (DocumentObject child in para.ChildObjects)
{
if (child is Break && (child as Break).BreakType == BreakType.PageBreak)
{
breakIndex = para.ChildObjects.IndexOf(child);
if (paraChild.ChildObjects.Count > 0)
c.ChildObjects.Add(obj);
Paragraph breakPara = para.Clone() as Paragraph;
breakPara.ChildObjects.Clear();
breakPara.ChildObjects.Add(child.Clone());
foreach (Paragraph p in c.Paragraphs)
{ p.Format.KeepFollow = true; }
s.Tables.Add(t.Clone());
breakCount++;
c.ChildObjects.Clear();
s.Body.ChildObjects.Add(breakPara);
breakCount++;
paraChild.ChildObjects.Clear();
s.Body.ChildObjects.RemoveAt(0);
}
else
paraChild.ChildObjects.Add(child.Clone());
}
if (breakIndex < 0)
c.ChildObjects.Add(obj);
}
else
c.ChildObjects.Add(obj);
}
foreach (Paragraph p in c.Paragraphs)
{
p.Format.KeepFollow = true;
}
s.Tables.Add(t);
s.AddParagraph();
}
finalDoc.ImportContent(doc, false);
}
finalDoc.SaveToFile("output.docx", FileFormat.Docx2013);
finalDoc.SaveToFile("output.pdf", FileFormat.PDF);
finalDoc.Dispose();
// No Break
doc.LastSection.BreakCode = SectionBreakType.NoBreak;