我在我的项目中使用Aspose.Word库,并尝试将html转换为doc。我用这段代码添加了页码:
var builder = new DocumentBuilder(document);
HeaderFooter header = builder.CurrentSection.HeadersFooters[HeaderFooterType.FooterPrimary];
if (header == null)
{
header = new HeaderFooter(builder.CurrentSection.Document, HeaderFooterType.FooterPrimary);
builder.CurrentSection.HeadersFooters.Add(header);
}
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.PageSetup.PageStartingNumber = 1;
builder.PageSetup.RestartPageNumbering = true;
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.InsertField("PAGE", string.Empty);
builder.MoveToDocumentEnd();
页码位于页面的左上角。是否可以将它们放在右上角?提前谢谢
答案 0 :(得分:0)
请使用ParagraphFormat.Alignment属性来获取或设置段落的文本对齐方式。
Document document = new Document(MyDir + "in.html");
var builder = new DocumentBuilder(document);
HeaderFooter header = builder.CurrentSection.HeadersFooters[HeaderFooterType.FooterPrimary];
if (header == null)
{
header = new HeaderFooter(builder.CurrentSection.Document, HeaderFooterType.FooterPrimary);
builder.CurrentSection.HeadersFooters.Add(header);
}
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.PageSetup.PageStartingNumber = 1;
builder.PageSetup.RestartPageNumbering = true;
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
//Use following line to get the required output.
builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
builder.InsertField("PAGE", string.Empty);
builder.MoveToDocumentEnd();
我与Aspose一起担任开发人员传播者。