我使用Aspose.Word构建文档。我尝试在右边距添加页码。图像更好地解释它:
怎么做?
我目前的代码:
arg -> (constraints => result)
答案 0 :(得分:0)
在您的情况下,您需要在文档的页脚中添加文本框,在其中插入页码字段,并设置其位置。请使用以下修改后的代码示例来获得所需的输出。
var document = new Document();
DocumentBuilder _builder = new DocumentBuilder(document)
{
PageSetup =
{
Orientation = Orientation.Portrait,
PaperSize = Aspose.Words.PaperSize.A4,
RightMargin = ConvertUtil.MillimeterToPoint(20),
BottomMargin = ConvertUtil.MillimeterToPoint(35),
LeftMargin = ConvertUtil.MillimeterToPoint(35),
TopMargin = ConvertUtil.MillimeterToPoint(35)
}
};
_builder.StartTable();
_builder.InsertCell();
_builder.Write("Test test test");
_builder.EndTable();
_builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
Shape shape = new Shape(document, ShapeType.TextBox);
shape.Stroked = false;
shape.Width = _builder.CurrentSection.PageSetup.PageWidth;
shape.Height = 50;
shape.Left = 0;
shape.Left = - _builder.CurrentSection.PageSetup.LeftMargin;
shape.Top = 0;
Paragraph paragraph = new Paragraph(document);
shape.AppendChild(paragraph);
_builder.InsertNode(shape);
_builder.MoveTo(paragraph);
_builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
_builder.Write("Pages: ");
_builder.InsertField("PAGE", "");
_builder.Write("/");
_builder.InsertField("NUMPAGES");
document.Save(MyDir + "output.pdf", SaveFormat.Pdf);
我与Aspose一起担任开发人员传播者。