如何在没有DocumentBuilder的情况下插入分页符?

时间:2016-08-26 06:20:14

标签: java aspose aspose.words

我有一个包含页眉/页脚的模板文档我必须插入多个文档。在每个文档之后,我需要插入一个分页符。

insertDocument()中有insertBreak()com.aspose.words.DocumentBuilder

我更愿意使用com.aspose.words.NodeImporter,因为它更灵活。这很好但我找不到一种方法可以在之后插入分页符。

是否有其他方法可以插入内容(例如段落,中断)而不是使用DocumentBuilder

2 个答案:

答案 0 :(得分:1)

请使用以下方法:

[["red", "red" "blank"],
["red", "red", "blank"], 
["blank", "blank", "blank"]

[["blank", "blank", "blank"],
["blank", "red", "red"],
["blank", "red", "red"]]

我与Aspose一起担任开发者布道者。

答案 1 :(得分:1)

请尝试使用以下代码:

Document doc = new Document(filePath);
NodeCollection col = doc.GetChildNodes(NodeType.Paragraph, true);
Paragraph para = (Paragraph)col[col.Count - 2];
Table tab = (Table)para.GetAncestor(NodeType.Table);
if (tab != null)
{
    // it means last para is inside table
    Paragraph newPara = new Paragraph(doc);
    newPara.Runs.Add(new Run(doc, ControlChar.PageBreak));
    newPara.ParagraphBreakFont.Size = 1;
    tab.ParentNode.InsertAfter(newPara, tab);
}else
{
    // normal case
}
doc.Save(MyDir + @"16.7.0.docx");

我与Aspose一起担任开发者布道者。

相关问题