News Category

Text

Text (19)

Add underline text in PDF in C#

2014-12-23 08:15:41 Written by support iceblue

Adding text into the PDF files is one of the most important requirements for developers. With the help of Spire.PDF, developer can draw transform text, alignment text and rotate text in PDF files easily. This tutorial will show you how to add underline text in C#.

By using the method canvas.drawstring offered by Spire.PDF, developers can set the position, font, brush and style for the adding texts. With the PdfFontStyle, developers can set the style to underline, bold, italic, regular and strikeout. Here comes to the code snippet of how to add underline text in PDF.

Step 1: Create a new PDF document.

PdfDocument pdf = new PdfDocument();

Step 2: Add a new page to the PDF file.

PdfPageBase page = pdf.Pages.Add();

Step 3: Create a true type font with size 20f, underline style.

PdfTrueTypeFont font = new PdfTrueTypeFont(@"C:\WINDOWS\Fonts\CONSOLA.TTF", 20f, PdfFontStyle.Underline);

Step 4: Create a blue brush.

PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);

Step 5: Draw the text string at the specified location with the specified Brush and Font objects.

page.Canvas.DrawString("Hello E-iceblue Support Team", font, brush, new PointF(10, 10));

Step 6: Save the PDF file.

pdf.SaveToFile("Result.pdf", FileFormat.PDF);

Effective screenshot:

How to add underline text in PDF in C#

Full codes:

using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;


namespace AddUnderlinetext
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument pdf = new PdfDocument();
            PdfPageBase page = pdf.Pages.Add();
            PdfTrueTypeFont font = new PdfTrueTypeFont(@"C:\WINDOWS\Fonts\CONSOLA.TTF", 20f, PdfFontStyle.Underline);
            PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);
            page.Canvas.DrawString("Hello E-iceblue Support Team", font, brush, new PointF(10, 10));
            pdf.SaveToFile("Result.pdf", FileFormat.PDF);
        }
    }
}

The task of searching for specific text within a PDF document and highlighting it serves as a valuable function across various situations. Whether you aim to find critical information, make annotations on significant details, or extract specific content, the capability to locate and highlight text within a PDF significantly enhances productivity and understanding.

This article provides guidance on how to effectively find and highlight text in a PDF document in C# using Spire.PDF for .NET.

Install Spire.PDF for .NET

To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.PDF

Find and Highlight Text in a Specific PDF Page in C#

Spire.PDF provides the PdfTextFinder class, which allows users to search for specific text within a page. By utilizing the Options property of this class, users have the ability to define search options such as WholeWord, IgnoreCase, and Regex. When utilizing the Find method of the class, users can locate all occurrences of the searched text within a page.

The following are the steps to find and highlight text in a specific PDF page in C#.

  • Create a PdfDocument object.
  • Load a PDF file from a given path.
  • Get a specific page from the document.
  • Create a PdfTextFinder object based on the page.
  • Specify search options using PdfTextFinder.Options property.
  • Find all instance of searched text using PdfTextFinder.Find() method.
  • Iterate through the find results, and highlight each instance using PdfTextFragment.Highlight() method.
  • Save the document to a different PDF file.
  • C#
using Spire.Pdf;
using Spire.Pdf.Texts;
using System.Drawing;

namespace FindAndHighlightTextInPage
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a PdfDocument object
            PdfDocument doc = new PdfDocument();

            // Load a PDF file
            doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Input.pdf");

            // Get a specific page
            PdfPageBase page = doc.Pages[1];

            // Create a PdfTextFinder object based on the page
            PdfTextFinder finder = new PdfTextFinder(page);

            // Specify the find options
            finder.Options.Parameter = TextFindParameter.WholeWord;
            finder.Options.Parameter = TextFindParameter.IgnoreCase;

            // Find the instances of the specified text
            List finds = finder.Find(".NET Framework");

            // Iterate through the find results
            foreach (PdfTextFragment fragment in finds)
            {
                // Highlight text
                fragment.HighLight(Color.LightYellow);
            }

            // Save to a different PDF file
            doc.SaveToFile("HighlightTextInPage.pdf", FileFormat.PDF);

            // Dispose resources
            doc.Dispose();
        }
    }
}

C#: Find and Highlight Text in PDF

Find and Highlight Text in a Rectangular Area in C#

By highlighting text within a rectangular area of a page, users can draw attention to a specific section or piece of information within the document. To specify a rectangular area, you can use the Options.Area property.

The following are the steps to find and highlight text in a rectangular area in C#.

  • Create a PdfDocument object.
  • Load a PDF file from a given path.
  • Get a specific page from the document.
  • Create a PdfTextFinder object based on the page.
  • Specify a rectangular area to search text using PdfTextFinder.Options.Area property.
  • Find all instance of searched text within the rectangular area using PdfTextFinder.Find() method.
  • Iterate through the find results, and highlight each instance using PdfTextFragment.Highlight() method.
  • Save the document to a different PDF file.
  • C#
using Spire.Pdf;
using Spire.Pdf.Texts;
using System.Drawing;

namespace FindAndHighlightTextInRectangularArea
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a PdfDocument object
            PdfDocument doc = new PdfDocument();

            // Load a PDF file
            doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Input.pdf");

            // Get a specific page
            PdfPageBase page = doc.Pages[1];

            // Create a PdfTextFinder object based on the page
            PdfTextFinder finder = new PdfTextFinder(page);

            // Specify a rectangular area for searching text
            finder.Options.Area = new RectangleF(0, 0, 841, 200);

            // Specify other options
            finder.Options.Parameter = TextFindParameter.WholeWord;
            finder.Options.Parameter = TextFindParameter.IgnoreCase;

            // Find the instances of the specified text
            List finds = finder.Find(".NET Framework");

            // Iterate through the find results
            foreach (PdfTextFragment fragment in finds)
            {
                // Highlight text
                fragment.HighLight(Color.LightYellow);
            }

            // Save to a different PDF file
            doc.SaveToFile("HighlightTextInRectangularArea.pdf", FileFormat.PDF);

            // Dispose resources
            doc.Dispose();
        }
    }
}

C#: Find and Highlight Text in PDF

Find and Highlight Text in an Entire PDF Document in C#

The initial code example illustrates how to highlight text in a specific page. To extend this functionality and find and highlight text throughout the entire document, you can iterate through each page of the document and sequentially apply the highlighting to the searched text.

The steps to find and highlight text in an entire PDF document using C# are as follows.

  • Create a PdfDocument object.
  • Load a PDF file from a given path.
  • Iterate through each page in the document.
    • Create a PdfTextFinder object based on a certain page.
    • Specify search options using PdfTextFinder.Options property.
    • Find all instance of searched text using PdfTextFinder.Find() method.
    • Iterate through the find results, and highlight each instance using PdfTextFragment.Highlight() method.
  • Save the document to a different PDF file.
  • C#
using Spire.Pdf;
using Spire.Pdf.Texts;
using System.Drawing;

namespace FindAndHighlightTextInDocument
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a PdfDocument object
            PdfDocument doc = new PdfDocument();

            // Load a PDF file
            doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Input.pdf");

            // Iterate through each page of the document
            foreach(PdfPageBase page in doc.Pages){

                // Create a PdfTextFinder object for the current page
                PdfTextFinder finder = new PdfTextFinder(page);

                // Specify the find options
                finder.Options.Parameter = TextFindParameter.WholeWord;
                finder.Options.Parameter = TextFindParameter.IgnoreCase;

                // Find the instances of the specified text
                Listfinds = finder.Find(".NET Framework");

                // Iterate through the find results
                foreach (PdfTextFragment fragment in finds)
                {
                    // Highlight text
                    fragment.HighLight(Color.LightYellow);
                }
            }

            // Save to a different PDF file
            doc.SaveToFile("HighlightAll.pdf", FileFormat.PDF);

            // Dispose resources
            doc.Dispose();
        }
    }
}

Find and Highlight Text in PDF Using a Regular Expression in C#

When searching for text in a document, using regular expressions can provide more flexibility and control over the search criteria. To utilize a regular expression, you need to configure the PdfTextFinder.Options.Parameter property to TextFindParameter.Regex, and provide the regular expression pattern as an input to the Find() method.

Here are the steps to find and highlight text in PDF using a regular expression in C#.

  • Create a PdfDocument object.
  • Load a PDF file from a given path.
  • Iterate through each page in the document.
    • Create a PdfTextFinder object based on a certain page.
    • Set the PdfTextFinder.Options.Parameter property to TextFindParameter.Regex.
    • Create a regular expression pattern that matches the specific text patterns you are seeking.
    • Find all instance of the searched text using PdfTextFinder.Find() method.
    • Iterate through the find results, and highlight each instance using PdfTextFragment.Highlight() method.
  • Save the document to a different PDF file.
  • C#
using Spire.Pdf;
using Spire.Pdf.Texts;
using System.Drawing;

namespace FindAndHighlightUsingRegularExpression
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a PdfDocument object
            PdfDocument doc = new PdfDocument();

            // Load a PDF file
            doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Input.pdf");

            // Iterate through each page of the document
            foreach (PdfPageBase page in doc.Pages)
            {
                // Create a PdfTextFinder object based on the page
                PdfTextFinder finder = new PdfTextFinder(page);

                // Specify the search model as Regex
                finder.Options.Parameter = TextFindParameter.Regex;

                // Find the text that conforms to a regular expression
                string pattern = @"\bM\w*t\b";
                List finds = finder.Find(pattern);

                // Iterate through the find results
                foreach (PdfTextFragment fragment in finds)
                {
                    // Highlight text
                    fragment.HighLight(Color.LightYellow);
                }
            }

            // Save to a different PDF file
            doc.SaveToFile("HighlightTextUsingRegex.pdf", FileFormat.PDF);

            // Dispose resources
            doc.Dispose();
        }
    }
}

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Draw text in PDF document is an important part and it is not easy to finish. With the help of Spire.PDF, a PDF component, you can not only draw text in PDF document easily for .NET and WPF, you can do this job easily for Silverlight.

We have introduced how to draw text for PDF .NET and PDF WPF. This article will give clear information of how to draw text with C# code for Silverlight.

Make sure Spire.PDF (or Spire.Office) has been installed correctly. Add Spire.PDF.dll as reference in the downloaded Bin folder though the below path: "..\Spire.PDF\Bin\Silverlight4\ Spire.PDF.dll".

Here comes to the steps:

Step 1: Create a PDF document and a page

[C#]
//create a pdf document
PdfDocument document = new PdfDocument();
//create one page
PdfPageBase page = document.Pages.Add();

Step 2: Draw Text

[C#]
//Draw Text - alignment
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 20f);
PdfSolidBrush brush = new PdfSolidBrush(Color.FromArgb(10, 0, 255, 0));

PdfStringFormat leftAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
page.Canvas.DrawString("Left!", font, brush, 0, 20, leftAlignment);
page.Canvas.DrawString("Left!", font, brush, 0, 50, leftAlignment);

PdfStringFormat rightAlignment = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
page.Canvas.DrawString("Right!", font, brush, page.Canvas.ClientSize.Width, 30, rightAlignment);
page.Canvas.DrawString("Right!", font, brush, page.Canvas.ClientSize.Width, 60, rightAlignment);

PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, page.Canvas.ClientSize.Width / 2, 40, centerAlignment);

//Draw the text - align in rectangle
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 10f);
PdfSolidBrush brush = new PdfSolidBrush(Color.FromArgb(10, 0, 0, 255));
RectangleF rctg1 = new RectangleF(0, 70, page.Canvas.ClientSize.Width / 2, 100);
RectangleF rctg2 = new RectangleF(page.Canvas.ClientSize.Width / 2, 70, page.Canvas.ClientSize.Width / 2, 100);
page.Canvas.DrawRectangle(new PdfSolidBrush(Color.FromArgb(1, 0, 0, 100)), rctg1);
page.Canvas.DrawRectangle(new PdfSolidBrush(Color.FromArgb(1, 0, 0, 150)), rctg2);

PdfStringFormat leftAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Top);
page.Canvas.DrawString("Left! Left!", font, brush, rctg1, leftAlignment);
page.Canvas.DrawString("Left! Left!", font, brush, rctg2, leftAlignment);

PdfStringFormat rightAlignment = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
page.Canvas.DrawString("Right! Right!", font, brush, rctg1, rightAlignment);
page.Canvas.DrawString("Right! Right!", font, brush, rctg2, rightAlignment);

PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Bottom);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, rctg1, centerAlignment);
page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, rctg2, centerAlignment);

//Draw text - brush
String text = "Go! Turn Around! Go! Go! Go!";
PdfPen pen = PdfPens.DeepSkyBlue;
PdfSolidBrush brush = new PdfSolidBrush(Color.FromArgb(10, 0, 0, 0));
PdfStringFormat format = new PdfStringFormat();
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 18f, PdfFontStyle.Italic);
SizeF size = font.MeasureString(text, format);
RectangleF rctg= new RectangleF(page.Canvas.ClientSize.Width / 2 + 10, 180,
size.Width / 3 * 2, size.Height * 2);
page.Canvas.DrawString(text, font, pen, brush, rctg, format);

Step 3: Save the document to stream

[C#]
using (Stream ms = saveFiledialog.OpenFile())
{
    document.SaveToStream(ms);

}

Now check the effective screenshot:

Draw_Text_in_PDF_Document_for_Silverlight.png

Draw PDF Barcode in C#/VB.NET

2011-12-15 02:52:53 Written by support iceblue

PDF Barcode is an optical machine-readable representation of data that shows data about the object to which it attaches. It is universally used to automate supermarket checkout systems. This section will introduce a solution to draw PDF barcode via a .NET PDF component in C#, VB.NET.

Spire.PDF for .NET which implements rich capabilities to create, edit and manipulate PDF files on .NET enables you to not only to draw PDF barcode but also set the format of the PDF barcode in C#, VB.NET. By creating an instance of Spire.Pdf.Barcode.PdfCodaBar class, you can draw PDF barcode. After that, you can set barcode format and some properties such as text display location, color etc. Please see effect as below picture:

Draw Barcode in PDF

Here you can download Spire.PDF for .NET and install it on your system. Before viewing the key code, please do not forget to add Spire.Pdf reference in your project.

[C#]
           //draw Codabar
            PdfTextWidget text = new PdfTextWidget();
            text.Font = font1;
            text.Text = "Codabar:";
            PdfLayoutResult result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCodabarBarcode barcode1 = new PdfCodabarBarcode("00:12-3456/7890");
            barcode1.BarcodeToTextGapHeight = 1f;
            barcode1.EnableCheckDigit = true;
            barcode1.ShowCheckDigit = true;
            barcode1.TextDisplayLocation = TextLocation.Bottom;
            barcode1.TextColor = Color.Green;
            barcode1.Draw(page, new PointF(0, y));
            y = barcode1.Bounds.Bottom + 5;


            //draw Barcode
            text.Text = "Code123:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode11Barcode barcode2 = new PdfCode11Barcode("123-4567890");
            barcode2.BarcodeToTextGapHeight = 1f;
            barcode2.TextDisplayLocation = TextLocation.Bottom;
            barcode2.TextColor = Color.OrangeRed;
            barcode2.Draw(page, new PointF(0, y));
            y = barcode2.Bounds.Bottom + 5;
[VB.NET]
'draw Codabar
Dim text As New PdfTextWidget()
text.Font = font1
text.Text = "Codabar:"
Dim result As PdfLayoutResult = text.Draw(page, 0, y)
page = result.Page
y = result.Bounds.Bottom + 2

Dim barcode1 As New PdfCodabarBarcode("00:12-3456/7890")
barcode1.BarcodeToTextGapHeight = 1F
barcode1.EnableCheckDigit = True
barcode1.ShowCheckDigit = True
barcode1.TextDisplayLocation = TextLocation.Bottom
barcode1.TextColor = Color.Green
barcode1.Draw(page, New PointF(0, y))
y = barcode1.Bounds.Bottom + 5

'draw Barcode
text.Text = "Code123:"
result = text.Draw(page, 0, y)
page = result.Page
y = result.Bounds.Bottom + 2

Dim barcode2 As New PdfCode11Barcode("123-4567890")
barcode2.BarcodeToTextGapHeight = 1F
barcode2.TextDisplayLocation = TextLocation.Bottom
barcode2.TextColor = Color.OrangeRed
barcode2.Draw(page, New PointF(0, y))
y = barcode2.Bounds.Bottom + 5

Spire.PDF for .NET is a professional PDF component which enables you to perform a wide range of PDF tasks in your .NET applications such as create, read, edit, write etc

Spire.PDF owns the ability of drawing text in PDF document. It supports text formatting, multilingual and text extraction. Here we will introduce how to draw text in PDF with different styles. Spire.PDF enables users to draw rotate text in PDF, draw transform text in PDF, draw alignment text in PDF, draw alignment text in rectangle and other style settings such as font, size, color, pen, etc.

Download Spire.PDF (Spire.Office) and install on system. Create project in visual studio, add Spire.PDF dll and system.drawing as reference. The following code can help us create a blank PDF document, PDF page and save the result PDF document. We can also find the solutions here.

        static void Main(string[] args)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            // Create one page
            PdfPageBase page = doc.Pages.Add();

            RotateText(page);

            //Save doc file.
            doc.SaveToFile("DrawText.pdf");
            doc.Close();

            //Launching the Pdf file.
            System.Diagnostics.Process.Start("DrawText.pdf");
        }

Draw Transform Text in PDF

To draw transform text in PDF, we can set scale transform and skew transform. Furthermore, we can also design font and color. Sample Code:

        private static void TransformText(PdfPageBase page)
        {
            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw the text - transform           
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 18f);
            PdfSolidBrush brush1 = new PdfSolidBrush(Color.DeepSkyBlue);
            PdfSolidBrush brush2 = new PdfSolidBrush(Color.CadetBlue);

            page.Canvas.TranslateTransform(20, 200);
            page.Canvas.ScaleTransform(1f, 0.6f);
            page.Canvas.SkewTransform(-10, 0);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush1, 0, 0);

            page.Canvas.SkewTransform(10, 0);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, 0);

            page.Canvas.ScaleTransform(1f, -1f);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, -2 * 18);
            //restor graphics
            page.Canvas.Restore(state);
        }

Effective Screenshot:

Draw Text in PDF

Draw Alignment Text in PDF

Usually we have 3 types of alignment on PDF text, left alignment, right alignment and center alignment. Sample code:

        private static void AlignText(PdfPageBase page)
        {
            //Draw the text - alignment
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 20f);
            PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);

            PdfStringFormat leftAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            page.Canvas.DrawString("Left!", font, brush, 0, 20, leftAlignment);
            page.Canvas.DrawString("Left!", font, brush, 0, 50, leftAlignment);

            PdfStringFormat rightAlignment = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            page.Canvas.DrawString("Right!", font, brush, page.Canvas.ClientSize.Width, 30, rightAlignment);
            page.Canvas.DrawString("Right!", font, brush, page.Canvas.ClientSize.Width, 60, rightAlignment);

            PdfStringFormat centerAlignment
                = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!",
                font, brush, page.Canvas.ClientSize.Width / 2, 40, centerAlignment);
        }

Effective Screenshot:

Draw Text in PDF

Draw alignment Text in a Rectangle

Draw alignment text in a rectangle means there has rectangles in PDF document and we will draw text in the rectangles and set alignment style. Sample Code:

        private static void AlignTextInRectangle(PdfPageBase page)
        {
            //Draw the text - align in rectangle
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 10f);
            PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);
            RectangleF rctg1 = new RectangleF(0, 70, page.Canvas.ClientSize.Width / 2, 100);
            RectangleF rctg2
                = new RectangleF(page.Canvas.ClientSize.Width / 2, 70, page.Canvas.ClientSize.Width / 2, 100);
            page.Canvas.DrawRectangle(new PdfSolidBrush(Color.LightBlue), rctg1);
            page.Canvas.DrawRectangle(new PdfSolidBrush(Color.LightSkyBlue), rctg2);

            PdfStringFormat leftAlignment
                = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Top);
            page.Canvas.DrawString("Left! Left!", font, brush, rctg1, leftAlignment);
            page.Canvas.DrawString("Left! Left!", font, brush, rctg2, leftAlignment);

            PdfStringFormat rightAlignment
                = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            page.Canvas.DrawString("Right! Right!", font, brush, rctg1, rightAlignment);
            page.Canvas.DrawString("Right! Right!", font, brush, rctg2, rightAlignment);

            PdfStringFormat centerAlignment
                = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Bottom);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, rctg1, centerAlignment);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, rctg2, centerAlignment);
        }

Effective Screenshot:

Draw Text in PDF

Draw Rotate Text in PDF

To draw rotate text in PDF, we should set the text as center alignment first. In addition, we can also set transform text here. Sample Code:

        private static void RotateText(PdfPageBase page)
        {
            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw the text - transform           
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 10f);
            PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);

            PdfStringFormat centerAlignment
                = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            float x = page.Canvas.ClientSize.Width / 2;
            float y = 380;

            page.Canvas.TranslateTransform(x, y);
            for (int i = 0; i < 12; i++)
            {
                page.Canvas.RotateTransform(30);
                page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, 20, 0, centerAlignment);
            }

            //restor graphics
            page.Canvas.Restore(state);
        }

Effective Screenshot:

Draw Text in PDF

Page 2 of 2