Aspose.PDF  for .NET

Work with Text from PDF via C#

Build your own .NET apps with various text manipulation in document files using .NET APIs.

Add a Text Paragraphs to PDF Document Using C#

In order to add Text to PDF file, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy to use document manipulation API for C# platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command

    PM> Install-Package Aspose.PDF

Add a Text to PDF Document via C#

You need aspose.pdf.dll to try the code in your environment.

  • Open a PDF document using Document object.
  • Create a TextParagraph and define its properties.
  • Add the TextParagraph to Page using TextBuilder.
  • Save the file again

System Requirements

Aspose.PDF for .NET is supported on all major operating systems. Just make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with .NET Framework, .NET Core, and PHP, VBScript, Delphi, C++ via COM Interop.
  • Development environment like Microsoft Visual Studio.
  • Aspose.PDF for .NET DLL referenced in your project.

Add a Text to PDF Document - C#

    // Open document
    Document doc = new Document();
    // Add page to pages collection of Document object
    Page page = doc.Pages.Add();
    TextBuilder builder = new TextBuilder(page);
    // Create text paragraph
    TextParagraph paragraph = new TextParagraph();
    // Set subsequent lines indent
    paragraph.SubsequentLinesIndent = 20;
    // Specify the location to add TextParagraph
    paragraph.Rectangle = new Aspose.Pdf.Rectangle(100, 300, 200, 700);
    // Specify word wraping mode
    paragraph.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords;
    // Create text fragment
    TextFragment fragment1 = new TextFragment("the quick brown fox jumps over the lazy dog");
    fragment1.TextState.Font = FontRepository.FindFont("Times New Roman");
    fragment1.TextState.FontSize = 12;
    // Add fragment to paragraph
    // Add paragraph

    dataDir = dataDir + "AddTextUsingTextParagraph_out.pdf";

    // Save resulting PDF document.
  • About Aspose.PDF for .NET API

    Aspose.PDF API can be used for PDF document manipulation and parsing within applications. One can create, modify, compress, secure, print or save PDF to TXT, HTML, PCL, XFA, XML, XPS, EPUB, TEX, Images and more formats. Aspose.PDF is a standalone API and it does not depend on any software including Adobe Acrobat.

    PDF What is PDF File Format

    Portable Document Format (PDF) is a type of document created by Adobe back in 1990s. The purpose of this file format was to introduce a standard for representation of documents and other reference material in a format that is independent of application software, hardware as well as Operating System. PDF files can be opened in Adobe Acrobat Reader/Writer as well in most modern browsers like Chrome, Safari, Firefox via extensions/plug-ins. Most of the commercially available software suites also offer conversion of their documents to PDF file format without the requirement of any additional software component. Thus, PDF file format has full capability to contain information like text, images, hyperlinks, form-fields, rich media, digital signatures, attachments, metadata, Geospatial features and 3D objects in it that can become as part of source document.

    Read More