0

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

中有一个insertDocument()和一个insertBreak()com.aspose.words.DocumentBuilder

我更喜欢使用,com.aspose.words.NodeImporter因为它更灵活。这工作正常,但我找不到事后插入分页符的方法。

除了使用DocumentBuilder?

4

2 回答 2

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 一起担任开发人员宣传员。

于 2016-08-30T07:14:37.920 回答
1

请使用以下方法:

doc.FirstSection.Body.FirstParagraph.Runs.Add(new Run(doc, ControlChar.PageBreak));

我与 Aspose 一起担任开发人员宣传员。

于 2016-08-29T03:52:24.963 回答