0

我在我的项目中使用 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();

页码位于页面的左上角。是否可以将它们放置在右上角?先感谢您

4

1 回答 1

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 合作,担任开发人员传道者。

于 2016-10-10T16:13:00.410 回答