Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created March 18, 2025 12:06
Show Gist options
  • Save bjoerntx/54e2ceda41a59b80e42c751ee1c8e2ae to your computer and use it in GitHub Desktop.
Save bjoerntx/54e2ceda41a59b80e42c751ee1c8e2ae 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.pdf", StreamType.AdobePDF);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment