// Get the current section to work with.
TXTextControl.Section currentSection = textControl1.Sections.GetItem();
// Get the current header.
TXTextControl.HeaderFooter currentHeader =
currentSection.HeadersAndFooters.GetItem(TXTextControl.HeaderFooterType.Header);
// Check if there is already a header present.
if (currentHeader == null)
{ // no header found in the current section, so we will add one.
currentSection.HeadersAndFooters.Add(TXTextControl.HeaderFooterType.Header);
currentHeader = currentSection.HeadersAndFooters.GetItem(TXTextControl.HeaderFooterType.Header);
}
// Add image to the header with alignment to the right page border.
//currentHeader.Images.Add(new TXTextControl.Image(),
// TXTextControl.HorizontalAlignment.Right,
// 0,
// TXTextControl.ImageInsertionMode.DisplaceText);
// Add some text to the header, left aligned.
currentHeader.Selection.Text = "This is a header with an image aligned to the right.";
TXTextControl.HeaderFooter currentFooter =
currentSection.HeadersAndFooters.GetItem(TXTextControl.HeaderFooterType.Footer);
if (currentFooter == null)
{
currentSection.HeadersAndFooters.Add(TXTextControl.HeaderFooterType.Footer);
currentFooter = currentSection.HeadersAndFooters.GetItem(TXTextControl.HeaderFooterType.Footer);
}
currentFooter.Selection.Text = "Page ";
// Add PageNumberField text field to the footer to display the current page number.
//这里设置其实页码为3,但是界面看到的页码仍然是1开始
PageNumberField pNumberField = new TXTextControl.PageNumberField(3, TXTextControl.NumberFormat.ArabicNumbers);
//pNumberField.StartNumber = 3;
currentFooter.PageNumberFields.Add(pNumberField);
// Add static page count to the footer.
// PLEASE NOTE: You will have to update this number programmatically if the page count changes!
// Best solution would be to do that in the Changed event.
currentFooter.Selection.Text = " of " + textControl1.Pages.ToString();
// Center the footer content.
currentFooter.Selection.ParagraphFormat.Alignment = TXTextControl.HorizontalAlignment.Center;
|
|