Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Adding watermarks to printed pages

This source code snippet requires TX Text Control .NET
Author:TX Text Control Support Department
Language:C# .NET
Version:1.0
Released:January 25, 2008
Last modified:January 28, 2008
Requirements:TX Text Control .NET with Visual Studio 2005
Download code:tx_sample_watermark.zip Download [20.35 KB, ZIP]
Click to enlarge

As of TX Text Control 14.0, it is possible to add graphics, text or anything else the GDI+ supports to a printed page during the printing process. This allows you to add watermarks to the page, such as the commonly known variations "CONFIDENTIAL" or "DRAFT".

TX Text Control's Print method allows you to print into a PrintDocument or the System.Drawing.Printing namespace. This object provides the PrintPage event that can be used to manipulate the Graphics object.

The following code shows how to create a PrintDocument, how to attach the event and how the document is printed into the PrintDocument:

  1. PrintDocument printDoc = new PrintDocument();
  2. printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
  3.  
  4. textControl1.PrintPreview(printDoc);

In this event, a string could be added to the Graphics object. This sample adds the string "DRAFT VERSION" to every every page that is printed or previewed by TX Text Control:

  1. Graphics g = e.Graphics;
  2. g.TranslateTransform(200, 200);
  3. g.RotateTransform(e.PageSettings.Landscape ? 30 : 60);
  4. g.DrawString("DRAFT VERSION", new Font("Arial", 75, FontStyle.Bold), _
  5. new SolidBrush(Color.FromArgb(64, Color.Black)), 0, 0);

Note that at least TX Text Control .NET 14.0 trial version and Visual Studio .NET 2005 are required to run this sample.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place