Articles in this section
Category / Section

Enhance PDFs with Multi-Line Text Boxes

2 mins read

The Syncfusion Essential® PDF offers a high-performance .NET PDF library that allows you to create, read, and edit PDF documents efficiently. This guide demonstrates how to add a multi-line text box using the PdfTextBoxField in a PDF document

Steps to add a multiline text box in PDF document

  1. Create a Console Application: Set up a new console application project.
    Console App.png
  2. Install Syncfusion® Package: Add the Syncfusion.Pdf.Net.Core NuGet package to your console application.
    NuGet Package.png
  3. Include Required Namespaces: Add the following namespaces in Program.cs.

C#

using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Drawing;
using System.IO;
  1. Implement Multi-Line Text Box: Use the following code to create a multi-line text box in your PDF document

C#

// Create a new PDF document
PdfDocument document = new PdfDocument();
// Creates a new page and adds it to the document
PdfPage page = document.Pages.Add();
// Create a standard font to be used in the text field
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
// Create a text box field and add it to the page with a name
PdfTextBoxField textBoxField = new PdfTextBoxField(page, "FirstName");
// Set the bounds (position and size) of the text box field
textBoxField.Bounds = new RectangleF(0, 0, 200, 50);
// Enable multiline functionality for the text box (allows multiple lines of text)
textBoxField.Multiline = true;
// Set the initial text inside the text box field
textBoxField.Text = "Essential PDF allows you to create and manage the form (AcroForm) in PDF document by using PdfForm class. The PdfFormFieldCollection class represents the entire field collection of the form.";
// Add the text box field to the form field collection in the document
document.Form.Fields.Add(textBoxField);
// Create a FileStream to save the document
using (FileStream stream = new FileStream("Output.pdf", FileMode.Create, FileAccess.Write))
{
 // Save the PDF document to the file stream
 document.Save(stream);
}
// Close the document
document.Close(true);

A complete working sample can be downloaded from GitHub.

By executing the program, the output PDF document will be generated as shown below:

Output.png

Take a moment to peruse the documentation to learn how to add form fields in a PDF document.

Conclusion
I hope you enjoyed learning how to add a multi-line text box field to a PDF document.

You can refer to our ASP.NET Core PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET Core PDF example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied