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 Sep 17, 2014 2:49 pm
Hi
I am trying to insert text at the top of a document.
Due to the way the code works i need to insert this text after the document has been saved. Then send to print.
So far when i do this the code will go in after the document and the vbCrlf will move each line onto a new page instead of just a character return.
My code so far is:
Dim doc As New Spire.Doc.Document
doc.LoadFromFile(DocumentName)
If (Len(OfficeCopyText) > 0) Then
Dim tr As New TextRange(doc)
tr.CharacterFormat.Bold = True
tr.CharacterFormat.FontSize = 18
tr.CharacterFormat.TextColor = Color.Gray
tr = doc.AddSection.AddParagraph.AppendText("User Copy")
tr = doc.AddSection.AddParagraph.AppendText(vbCrLf)
tr = doc.AddSection.AddParagraph.AppendText(vbCrLf)
End If
Dim printDialog As New PrintDialog
doc.PrintDialog = printDialog
doc.PrintDocument.Print()
doc.Close()
I have attached a document of how i want it to look like, the text User Copy is what im trying to achieve at the top of the page with a character return.
Any ideas how to get this to work?
Login to view the files attached to this post.
-
stevenheggie
-
- Posts: 60
- Joined: Tue Jun 24, 2014 10:32 am
Thu Sep 18, 2014 6:35 am
Dear stevenheggie,
Thanks for your inquiry.
For your requirement, please refer to the following code:
- Code: Select all
Dim doc As New Document()
doc.LoadFromFile("Doc test.docx")
Dim tr As New TextRange(doc)
tr.CharacterFormat.Bold = True
tr.CharacterFormat.FontSize = 18
tr.CharacterFormat.TextColor = Color.Gray
tr.CharacterFormat.Italic = True
tr.Text = "User Copy" + vbCrLf
Dim section As Section = doc.Sections(0)
Dim para As Paragraph = section.Paragraphs(0)
Dim body As Body = para.OwnerTextBody
Dim addPar As New Paragraph(doc)
addPar.ChildObjects.Add(tr)
addPar.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right
Dim index As Integer = body.ChildObjects.IndexOf(para)
body.ChildObjects.Insert(index, addPar)
Dim dialog As New PrintDialog()
doc.PrintDialog = dialog
doc.PrintDocument.Print()
doc.SaveToFile("Result.docx")
Best regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
-
burning.liu
-
- Posts: 406
- Joined: Mon Aug 04, 2014 6:47 am
Mon Sep 22, 2014 9:11 am
Hello,
Has the issue been resolved? Could you please give us some feedback if convenience?
If there are any questions, welcome to get it back to us.
Thanks,
Gary
E-iceblue support team
-
Gary.zhang
-
- Posts: 1380
- Joined: Thu Apr 04, 2013 1:30 am
Mon Sep 22, 2014 3:01 pm
yes the issue is now resolved, many thanks
-
stevenheggie
-
- Posts: 60
- Joined: Tue Jun 24, 2014 10:32 am
Fri Oct 24, 2014 3:09 am
Hello,
Thanks for your response, if there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
-
Gary.zhang
-
- Posts: 1380
- Joined: Thu Apr 04, 2013 1:30 am