【C# 】Aspose.word 如何自定義頁眉上的頁碼

 

newdoc1.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;

//插入頁碼頁腳
 newdoc1.FirstSection.HeadersFooters.LinkToPrevious(true);
newdoc.AppendDocument(newdoc1, ImportFormatMode.KeepSourceFormatting);

String src = dataDir + "Page numbers.docx";

String dst = dataDir + "Page numbers_out.docx";

// Create a new document or load from disk

Aspose.Words.Document doc = new Aspose.Words.Document(src);

// Create a document builder

Aspose.Words.DocumentBuilder builder = new DocumentBuilder(doc);

// Go to the primary footer

builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);

// Add fields for current page number

builder.InsertField("PAGE""");

// Add any custom text

builder.Write(" / ");

// Add field for total page numbers in document

builder.InsertField("NUMPAGES""");

 

// Import new document

Aspose.Words.Document newDoc = new Aspose.Words.Document(dataDir + "new.docx");

// Link the header/footer of first section to previous document

newDoc.FirstSection.HeadersFooters.LinkToPrevious(true);

doc.AppendDocument(newDoc, ImportFormatMode.UseDestinationStyles);

// Save the document

doc.Save(dst);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章