Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Apr 22, 2015 11:30 am

Hello,
I have to insert a text in a word document at an exact position (horizontal and vertical coordinates) as well as we do with a textbox.
Do I have this possibility?
With 'Appendtext' I can't find a horizontal/verticalposition method...
thanks,
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Thu Apr 23, 2015 6:15 am

Dear Paola,

Thanks for your inquiry.
You can append a text box and then append text in it, please refer to the following code:
Code: Select all
 
            Document doc = new Document();
            Section sec = doc.AddSection();
            Paragraph par = sec.AddParagraph();
            Spire.Doc.Fields.TextBox textBox = par.AppendTextBox(50,50);
            Paragraph par1 = textBox.Body.AddParagraph();
            par1.AppendText("Hello, world");
            textBox.Format.TextWrappingStyle = TextWrappingStyle.InFrontOfText;
            textBox.Format.VerticalOrigin = VerticalOrigin.Margin;
            textBox.Format.VerticalPosition = 200;
            textBox.Format.HorizontalOrigin = HorizontalOrigin.Margin;
            textBox.Format.HorizontalPosition = 100;
            textBox.Format.LineColor = Color.White;
            doc.SaveToFile("result.docx", FileFormat.Docx);

Please feel free to contact us if you have any questions or needs.

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Thu Apr 23, 2015 7:48 am

Thank you very much for youe answer, it works fine!
I have another question - I created a CharacterFormat to use it as standard for more than one text-string in my document:

Dim fArialBold As New Spire.Doc.Formatting.CharacterFormat(MyDoc)
With fArialBold
.FontName = "Arial Narrow"
.FontSize = 9
.Bold = True
End With

I use this way:
Dim Riga As String = Space(20) & "THIS IS MY NEW STRING"
ParMeseAnno.AppendText(Riga).ApplyCharacterFormat(fArialBold)

and it works fine.
How can I define a characterformat to apply it to more than one textbox? I mean use it instead of....
textBox.Format.TextWrappingStyle = TextWrappingStyle.InFrontOfText;
textBox.Format.VerticalOrigin = VerticalOrigin.Margin;
textBox.Format.HorizontalOrigin = HorizontalOrigin.Margin;
textBox.Format.LineColor = Color.White;

Thank you again,
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Thu Apr 23, 2015 10:16 am

Hello,

Sorry that there is no way to define a characterformat to apply it to more than one textbox.

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Thu Apr 23, 2015 11:19 am

Thanks,

anyway these two lines don't work - they generate a syntax error:
textBox.Format.VerticalOrigin = VerticalOrigin.Margin;
textBox.Format.HorizontalOrigin = HorizontalOrigin.Margin;
Shall I "Import" something at the beginning of my document?

How can I set the border of my text boxes?
- My text boxes are high and large enough, but they hide the bottom of the written inside text....

thanks,
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Fri Apr 24, 2015 2:07 am

Dear Paola,

Please provide the code you used for us.
Thanks in advance.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Fri Apr 24, 2015 8:47 am

Dim tbMo As TextBox = ParMA.AppendTextBox(90, 15)
Dim parMo As Paragraph = tbMo.Body.AddParagraph()
parMo.AppendText("OCTOBER").ApplyCharacterFormat(fCourier)
tbMo.Format.HorizontalPosition = 350
tbMo.Format.VerticalPosition = 1
tbMo.Format.LineColor = Drawing.Color.Black
tbMo.Format.FillColor = Drawing.Color.LightGray

the fCourier character format is defined with this code:
Dim fCourier As New Spire.Doc.Formatting.CharacterFormat(MyDoc)
With fCourier
.FontName = "Courier New"
.FontSize = 10
.Bold = True
End With

I see the word "OCTOBER" in the textbox tbMo slightly hidden in then bottom part (as if the textbox tbMo had an "invisible" border which hides a bit the bottom of the word).
Thank you,
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Fri Apr 24, 2015 10:06 am

Hello,

Thanks for sharing.
The reason why the textbox tbMo slightly hidden in the bottom part is that the height of the textbox is not enough.
Please enlarge its height.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Fri Apr 24, 2015 10:19 am

Sorry but it's not so esay,
in another pdf document generated by a word document, with the same height of the textbox and of the text I used in this pdf, the text appears completely.
In the textbox generated by spire.doc (and ,pdf) there are internal upper and lower margins...how can I remove them?
These two lines give a syntax error:
textBox.Format.HorizontalOrigin = HorizontalOrigin.Margin
textBox.Format.VerticalOrigin = VerticalOrigin.Margin
shall I "Import" something at the beginning of the page?

thanks,
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Mon Apr 27, 2015 3:58 am

Hello,

Sorry for delay as weekend.
What is the information of syntax error? I did not encounter the error when using the two lines.
In addition, there is a default value of internal margin, and at present our product can’t set the value of internal margin because the property of the internal margin is not opened. When the property is opened, we will let you know.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Tue Apr 28, 2015 9:28 am

Hello,

I did not encounter the error when using the two lines, please provide the information of syntax error.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Wed Apr 29, 2015 9:19 am

Hello, sorry for the delay,
I solved the problem.
At the line:
MyTextBox.Format.VerticalOrigin = VerticalOrigin.Margin

the syntax errore was:
'VerticalOrigin' is ambiguous, imported from the namespaces or types 'Spire.Doc.Fields.DocPicture, Spire.Doc.Documents'

so I substituted it with:
MyTextBox.Format.VerticalOrigin = Spire.doc.documents.VerticalOrigin.Margin

best regards,
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Wed Apr 29, 2015 9:27 am

Dear Paola,

Thanks for your response.
I am glad to hear your issue has resolved, if there are any questions or needs, welcome to get it back to us.

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.Doc