Add Text to PDF C#

PDF files are widely used for various purposes, ranging from business documents to personal files. Sometimes you may need to insert or add text to an existing PDF file. In this blog post, we will explore how to perform this task using C#. You will learn how to insert text to PDF in C# or Online for free.

Add Text to PDF Online and Free

You can use this free PDF Editor to insert text into a PDF document. You can add the text on any page with different format options like setting the color, background color, font, size, position, etc. Simply access it from any device or operating system without any signup or login.

Insert Text in PDF – C# API Installation

You can insert text at any position on a PDF page while setting different properties to control text appearance like color, font, style, etc. You just need to setup Conholdate.Total for .NET by downloading it from the Releases page or install it using the NuGet command below:

Install-Package Conholdate.Total 

Moreover, there are different approaches to insert text in PDF documents using C#. For example, using a Text Fragment, Text Paragraph, HTML Segment, etc. each with its strengths and features. You can use any of these approaches to insert text as per your requirements.

Add Text to PDF using TextFragment in C#

You can easily add text to a PDF file using the TextFragment with the following steps:

  • Load an existing document or create a new one.
  • Access a specific page.
  • Create a text fragment and set different properties.
  • Create a TextBuilder object and append the text.
  • Save the output PDF document.

The code snippet below shows how to add text to PDF in C#:

Add Text to PDF with TextParagraph in C#

You can insert text in a PDF document at any position by following the steps below:

  • Open the source PDF document.
  • Create a text paragraph and set its position along with other properties.
  • Create and add a fragment to the paragraph.
  • Add the paragraph and save the output PDF file.

The following sample code shows how to add text to PDF with TextParagraph in C#:

Insert HTML Format String to PDF in C#

You can use HTML string to insert text in a PDF document as you can also set different text styles based on your requirements. Please follow the steps below to achieve these requirements in C#:

  • Load an input document or create a new one from scratch.
  • Add a new page or access an existing page.
  • Instantiate HtmlFragment with HTML contents.
  • Add HTML Fragment to paragraphs collection.
  • Save output PDF after appending text.

The code sample below demonstrates how to add text to PDF with HTML string in C#:

Get a Free Evaluation License

You can request a free temporary license to test the APIs without any evaluation restrictions.

Conholdate.Total for .NET - Learning Resources

You may visit the following sections to learn about more features and capabilities to work with PDF files and other documents:

Summing Up

In this blog post, you have explored different approaches to add text to a PDF file using C#. The online approach, on the other hand, focused on using online PDF editing services to accomplish the task without the need for coding. Depending on your requirements and preferences, you can choose the approach that suits you best. In case of any ambiguities, please contact us at the free support forum.

See Also