We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Insert Text At Specific Location of Header (x,y)

Dears, How do we insert Text at a specific Location let's say inside  Header of document only visible on only first Page.

Best Regards,

6 Replies

NI Nilofer June 30, 2017 04:38 PM UTC

Ok, some how got it done using & Text Box & below code; but how do we change font & color?

Dim txtSrNo As IWTextBox = (wordDocument.LastParagraph.AppendTextBox(300, 25))
'Set the alignment positions for text box using TextBoxFormat instance.
txtSrNo.TextBoxFormat.VerticalOrigin = VerticalOrigin.Page
txtSrNo.TextBoxFormat.VerticalPosition = 100
txtSrNo.TextBoxFormat.HorizontalOrigin = HorizontalOrigin.Page
txtSrNo.TextBoxFormat.HorizontalPosition = 100
txtSrNo.TextBoxFormat.TextWrappingStyle = TextWrappingStyle.InFrontOfText
txtSrNo.TextBoxFormat.NoLine = True
'Add the text inside the textbox textbody.
Dim textRange As IWTextRange = txtSrNo.TextBoxBody.AddParagraph().AppendText(x_SerialNo)


NI Nilofer June 30, 2017 06:09 PM UTC

Ok, Got it done! Just posting solution in case for someone similar problem

'Add the text box in particular size.

Dim txtSrNo As IWTextBox = (wordDocument.LastParagraph.AppendTextBox(240, 25)) 'Set the alignment positions for text box using TextBoxFormat instance. txtSrNo.TextBoxFormat.VerticalOrigin = VerticalOrigin.Page txtSrNo.TextBoxFormat.VerticalPosition = 129 txtSrNo.TextBoxFormat.HorizontalOrigin = HorizontalOrigin.Page txtSrNo.TextBoxFormat.HorizontalPosition = 350 txtSrNo.TextBoxFormat.TextWrappingStyle = TextWrappingStyle.InFrontOfText txtSrNo.TextBoxFormat.NoLine = True 'Add the text inside the textbox textbody. Dim textRange As IWTextRange = txtSrNo.TextBoxBody.AddParagraph().AppendText(x_SerialNo) With textRange .CharacterFormat.Bold = True .CharacterFormat.FontName = "Courier New" .CharacterFormat.TextColor = Color.Red End With


NI Nilofer July 2, 2017 02:17 PM UTC

This works well if one Page, but how to do in case of multiple pages :( This code is inserting on the last page.

I need it to insert only on First Page. Please Help.

Best Regards,



SY Sethumanikkam Yogendran Syncfusion Team July 3, 2017 05:23 AM UTC

Hi Nilofer,

Thank you for contacting Syncfusion support.

You can insert the text box in first page header of the Word document and set DifferentFirstPage Property as true from WPageSetup Class to meet your requirement. Please find the below code snippets for your reference.
 
' Sets DifferentFirstPage as true for inserting header and footer text.
wordDocument.Sections(0).PageSetup.DifferentFirstPage = True
' Inserts the text box in first page header.
Dim txtSrNo As IWTextBox = wordDocument.Sections(0).HeadersFooters.FirstPageHeader.AddParagraph().AppendTextBox(240, 25) 

Please refer the below UG link to know more about working with headers and footers.
https://help.syncfusion.com/file-formats/docio/working-with-sections#working-with-headers-and-footers

Please let us know if you have any other questions.

Regards,
Sethumanikkam.Y



NI Nilofer July 4, 2017 03:55 AM UTC

Thanks. It has been resolved.



SY Sethumanikkam Yogendran Syncfusion Team July 4, 2017 05:02 AM UTC

Hi Nilofer,

Thank you for your update.

We are glad to know that your issue has been resolved.

Please let us know if you need any further assistance. We are happy to assist you as always.

Regards,
Sethumanikkam.Y


Loader.
Up arrow icon