Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created October 25, 2024 13:14
Show Gist options
  • Save bjoerntx/ae7ce4b8f2314ff4b13f941bb6774ba1 to your computer and use it in GitHub Desktop.
Save bjoerntx/ae7ce4b8f2314ff4b13f941bb6774ba1 to your computer and use it in GitHub Desktop.
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