Add single-line text to PDF

Generate PDF, Manipulate PDF
11/2/2011

Downloads

[Visual Studio 2010 Sample Project.zip]: /support/articles/150/Visual Studio 2010 Sample Project.zip "Visual Studio 2010 Sample Project.zip" [example-of-single-line-text-to-pdf.png]: /support/articles/150/example-of-single-line-text-to-pdf.png "example-of-single-line-text-to-pdf.png" TextShape allows you to add single-line text to a PDF document.

![example-of-single-line-text-to-pdf.png]

Document document = new Document();
Page page = new Page( PageSize.Letter );
document.Pages.Add(page);

// Create a text shape to draw text
TextShape textShape = new TextShape(50, 750, "Hello World!", new TallComponents.PDF.Fonts.Font(), 16);
            
// Add the text to the page
page.Overlay.Add(textShape);
Dim document As New Document()
Dim page As New Page(PageSize.Letter)
document.Pages.Add(page)

' Create a text shape to draw text
Dim textShape As New TextShape(50, 750, "Hello World!", New TallComponents.PDF.Fonts.Font(), 16)

' Add the text to the page
page.Overlay.Add(textShape)

Since it is inherited from Shape, TextShapes can be drawn onto all kinds of canvas such as Page.Overlay, Page.Underlay, Page.VisualOverlay and Page.VisualUnderlay. In addition, the location of all kinds of Shapes can only be set in constructor. After that, the only way to change the location is through transformation. The following statement shows how to move the TextShape to (30, 700):

textShape.Transform = new TallComponents.PDF.Transforms.TranslateTransform(30, 700);
textShape.Transform = New TallComponents.PDF.Transforms.TranslateTransform(30, 700)