Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Watermark text in vb.net

Posted on 2009-02-23
12
Medium Priority
?
979 Views
Last Modified: 2013-11-18
I am adding a watermark text in a document in  VB.net  application.
But it is causing the text in the page to be printed on the next page and the watermark prints on the first page. In preview it is all fine.
 Why is it causing the text to jump to the next page?
Dim objSelection As Word.Selection
                    Dim waterText As Word.Shape
                    Dim oMissing As Object
                    oMissing = System.Reflection.Missing.Value
                    objSelection = Doc.ActiveWindow.Selection
                    Dim wordText As String = AppConstants.WATERMARK_TEXT
                    Doc.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader
                    waterText = objSelection.HeaderFooter.Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1, _
                     wordText, "Times New Roman", 1, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, 0, 0, oMissing)
                    'waterText = objSelection.Document.Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1, _
                    ' "DRAFT", "Times New Roman", 1, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, 0, 0, oMissing)
                    waterText.Select(oMissing)
                    'waterText.Select(objSelection)
                    objSelection.ShapeRange.Name = "PowerPlusWaterMarkObject1"
                    'objSelection.ShapeRange.TextEffect.NormalizedHeight = False
                    objSelection.ShapeRange.Fill.Transparency = 0.5
                    objSelection.ShapeRange.Line.Weight = 0.75
                    objSelection.ShapeRange.Rotation = 315
                    waterText.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue
                    waterText.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse
                    waterText.Fill.Solid()
                    waterText.Fill.ForeColor.RGB = Convert.ToInt32(Word.WdColor.wdColorGray30)
 
                    ' objSelection.ShapeRange.WrapFormat.AllowOverlap = True
                    objSelection.ShapeRange.WrapFormat.Side = Word.WdWrapType.wdWrapNone '           wdWrapNone
                    objSelection.ShapeRange.WrapFormat.Type = 3
                    objSelection.ShapeRange.LockAspectRatio = True
 
 
                    waterText.RelativeHorizontalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin
                    waterText.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin
                    waterText.Left = Convert.ToDouble(Word.WdShapePosition.wdShapeCenter)
                    waterText.Top = Convert.ToDouble(Word.WdShapePosition.wdShapeCenter)
                    waterText.Height = WordApp.InchesToPoints(1.42F)
                    waterText.Width = WordApp.InchesToPoints(4.0F)
                    Doc.ActiveWindow.ActivePane.VerticalPercentScrolled = 10
                    Doc.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument

Open in new window

0
Comment
Question by:jsonal
  • 5
  • 5
10 Comments
 
LVL 23

Expert Comment

by:irudyk
ID: 23755816
I tired you code and it seems to work for me.  Maybe try setting the objSelection after you active window's view to the current page header?

Dim objSelection As Word.Selection
Dim waterText As Word.Shape
Dim oMissing As Object
oMissing = System.Reflection.Missing.Value
 
'objSelection = Doc.ActiveWindow.Selection
 
Dim wordText As String = AppConstants.WATERMARK_TEXT
Doc.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader
 
objSelection = Doc.ActiveWindow.Selection
 
waterText = objSelection.HeaderFooter.Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1, _
wordText, "Times New Roman", 1, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, 0, 0, oMissing)
'waterText = objSelection.Document.Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1, _
' "DRAFT", "Times New Roman", 1, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, 0, 0, oMissing)
waterText.Select(oMissing)
'waterText.Select(objSelection)
objSelection.ShapeRange.Name = "PowerPlusWaterMarkObject1"
'objSelection.ShapeRange.TextEffect.NormalizedHeight = False
objSelection.ShapeRange.Fill.Transparency = 0.5
objSelection.ShapeRange.Line.Weight = 0.75
objSelection.ShapeRange.Rotation = 315
waterText.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue
waterText.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse
waterText.Fill.Solid()
waterText.Fill.ForeColor.RGB = Convert.ToInt32(Word.WdColor.wdColorGray30)
 
' objSelection.ShapeRange.WrapFormat.AllowOverlap = True
objSelection.ShapeRange.WrapFormat.Side = Word.WdWrapType.wdWrapNone '           wdWrapNone
objSelection.ShapeRange.WrapFormat.Type = 3
objSelection.ShapeRange.LockAspectRatio = True
 
 
waterText.RelativeHorizontalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin
waterText.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin
waterText.Left = Convert.ToDouble(Word.WdShapePosition.wdShapeCenter)
waterText.Top = Convert.ToDouble(Word.WdShapePosition.wdShapeCenter)
waterText.Height = WordApp.InchesToPoints(1.42F)
waterText.Width = WordApp.InchesToPoints(4.0F)
Doc.ActiveWindow.ActivePane.VerticalPercentScrolled = 10
Doc.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument

Open in new window

0
 

Author Comment

by:jsonal
ID: 23761645
Hi, Did you take the printout also? I mean did you add code to print this page ? While previewing it looks good but in the print the watermark takes the first page and the page content jumps to the next page.
0
 
LVL 23

Expert Comment

by:irudyk
ID: 23766194
No, I didn't do a print out.  Will have to give it a try on Monday and let you know if I get the same results, unless someone else here on EE can get you answer sooner :)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:irudyk
ID: 23783427
Okay, I ran the code and printed out the page.  Both the preview and the printed output came of fine...both had the text and watermark appear on the same page.  Maybe the printer you are sending it to is what's causing the issue.  Can you print to another printer or say to a PDF?  If so, do you get the same results?
0
 

Author Comment

by:jsonal
ID: 23791628
Actually I use the lpr command to print and looks like it is causing the issue. also I use Ecrion to convert document to postscript file.
0
 
LVL 23

Accepted Solution

by:
irudyk earned 1500 total points
ID: 23794349
Is there are reason you need to do all of that?  If you want to print the document from Word, could you not just use something like the following in your code?
     objDoc.PrintOut()
0
 

Author Comment

by:jsonal
ID: 23812652
Actually the application will run on the server without windows environment.  objDoc.printout wont work. we can close this question.
0
 
LVL 23

Expert Comment

by:irudyk
ID: 23813669
You say that the objDoc.PrintOut wont work.  Hmm, well the code you are using above uses the Word application object upon which the objDoc object is based upon.  So, how you figure objDoc.PrintOut won't work is not clear to me since PrintOut is a method applicable to the Word application document object.
Of course, in your particular code the object might not be called objDoc. It looks like you are using an object called Doc. So Doc.PrintOut() would be what you would likely use.  Overall Doc.PrintOut should work just as you using Doc.ActiveWindow.ActivePane.View.SeekView likely works for you.
0
 

Author Closing Comment

by:jsonal
ID: 31550431
Actually I compose the document in client application and then it is saved in a server. The other application which picks the document and prints it is not running in windows environment.
0
 

Author Comment

by:jsonal
ID: 23827236
Actually I compose the document in client application and then it is saved in a server. The other application which picks the document and prints it is not running in windows environment./OS
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Starting up a Project
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question