Created
October 25, 2024 13:14
-
-
Save bjoerntx/ae7ce4b8f2314ff4b13f941bb6774ba1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using TXTextControl; | |
using (ServerTextControl tx = new ServerTextControl()) | |
{ | |
tx.Create(); | |
// Add a header | |
tx.Sections.GetItem().HeadersAndFooters.Add(HeaderFooterType.Header); | |
// Get the header/footer object | |
HeaderFooter headerFooter = tx.Sections.GetItem().HeadersAndFooters.GetItem(HeaderFooterType.Header); | |
// Add an image to the header | |
Image image = new Image("tx_logo.svg", 0); | |
headerFooter.Images.Add(image, HorizontalAlignment.Right, 1, ImageInsertionMode.AboveTheText); | |
// Add a text to the header | |
headerFooter.Selection.Text = "Header Text\r\n\r\n"; | |
// Add a page number field to the header | |
headerFooter.Selection.Text = "Page "; | |
headerFooter.PageNumberFields.Add(new PageNumberField()); | |
headerFooter.Selection.Text = " of "; | |
headerFooter.PageNumberFields.Add(new PageNumberField() { ShowNumberOfPages = true }); | |
// Add a new page | |
tx.Selection.Text = "\f"; | |
// Save the document | |
tx.Save("results.docx", StreamType.WordprocessingML); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment