Add Text or Formatted Text to a PDF
Adding text areas and formatted text areas to a PDF is a breeze when using DynamicPDF Core Suite for .NET. The following C# examples show you how.
How to Add TextArea to PDF
The following steps and C# sample code illustrate adding a TextArea
to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding TextArea to a PDF
- Create a
Document
object. - Create a
Page
object and add it to theDocument
instance. - Create a
TextArea
object with its required parameters. - Add the
TextArea
instance to thePage
instance. - Add the
Draw
method to output the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
TextArea textArea = new TextArea("This is the underlined " + "text of a TextArea", 100, 100, 400, 30, Font.HelveticaBoldOblique, 18);
textArea.Underline = true;
page.Elements.Add(textArea);
document.Draw(@"Output.pdf");
How to Add FormattedTextArea to PDF
The following steps and C# sample code illustrate adding a FormattedTextArea
to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding a FormattedTextArea
to a PDF Document
- Create a
Document
object. - Create a
Page
object and add it to theDocument
instance. - Create a
FormattedTextAreaStyle
object and add the formatting parameters to the constructor. - Create a
FormattedTextArea
and assign the text along with the style. - Add the
FormattedTextArea
to thePage
instance. - Add the
Draw
method to output the PDF document.
Sample Code - C#
// Create a PDF Document
Document document = new Document();
// Create a Page and add it to the document
Page page = new Page();
document.Pages.Add(page);
// Create an formatted style
FormattedTextAreaStyle style = new FormattedTextAreaStyle(FontFamily.Helvetica, 12, false);
// Create the text and the formatted text area
string formattedText = "<p>Formatted text area provide rich formatting support for text that " +
"appears in the document. You have complete control over 8 paragraph properties: " +
"spacing before, spacing after, first line indentation, left indentation, right " +
"indentation, alignment, allowing orphan lines, and white space preservation; 6 " +
"font properties: <font face='Times'>font face, </font><font " +
"pointSize='6'>font size, </font><font color='FF0000'>color, " +
"</font><b>bold, </b><i>italic and </i><u>" +
"underline</u>; and 2 line properties: leading, and leading type. Text can " +
"also be rotated.</p>";
FormattedTextArea formattedTextArea = new FormattedTextArea(formattedText, 0, 0, 256, 400, style);
// Add the formatted text area to the page
page.Elements.Add(formattedTextArea);
// Save the PDF
document.Draw(@"Output.pdf");
GitHub Project
An example project is available on GitHub (examples.dynamicpdf-core-suite-dotnet-core). Examples are provided in C# and VB.NET. Clone or view the example project at GitHub. This specific example discussed on this page are all contained in following classes on GitHub.
- C# - TextFormattingExample.cs
- VB.NET - TextFormattingExample.vb
Getting Started
Get started easily by installing DynamicPDF Core Suite for .NET through NuGet or manually. Then, refer to the documentation for more information on using and purchasing the product.
NuGet Package
The easiest way to install DynamicPDF Core Suite is by obtaining the NuGet package using Visual Studio's Package Manager. You can also obtain the NuGet package by downloading it directly. Refer to the installation documentation for more information.
DynamicPDF Core Suite for .NET Information
DynamicPDF Core Suite for .NET combines creating, merging, and visual report creation into one powerful product for creating PDF documents. It is ideal for anyone who needs to generate PDF documents or reports or work with existing PDFs in their applications. With a free Evaluation Edition to try and with flexible and royalty-free licensing options, why not start using DynamicPDF Core Suite for .NET today!
- DynamicPDF Core Suite for .NET Product Page
- [DynamicPDF Core Suite for .NET Documentation](/docs/dotnet/dynamic-pdf-core-suite-welcome ")
More Information on TextArea and FormattedTextArea
- Refer to the TextArea or FormattedTextArea documentation topic, or
- Chapter 4, Text, in the book DynamicPDF Core Suite for .NET by Example available on GitHub.
Available on Other Platforms
DynamicPDF Core Suite is also available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details.
- DynamicPDF Generator
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX
- DynamicPDF Merger
- Java - DynamicPDF Merger for Java
- COM/ActiveX - DynamicPDF Merger for COM/ActiveX