Edit PDF via C#

Advanced PDF Editor for .NET. Use Aspose.PDF to modify PDF documents programmatically

How to Edit PDF with C#

Do you need to edit PDF? Programmatic modification of PDF documents is an essential part of modern digital workflows. With .NET libraries like Aspose.PDF, developers can edit text in PDF, insert graphs using external data, modify tables and more. These libraries are stand-alone solutions that don’t rely on other software and are ready for commercial use. They cover all possible needs of professional C# developers.

  • Edit PDF elements: tables, texts, images,, fields, etc.
  • Edit PDF formatting attributes and styles
  • Add new elements
  • Work with graphs and forms

In order to edit PDF file, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy to use document manipulation API for net 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

PM > Install-Package Aspose.PDF

How to Edit PDF via C#


You need Aspose.PDF for .NET to try the code in your environment.

  1. Design and Develop your editor.
  2. Or use Aspose Editor by accessing its demo app using advanced WYSIWYG editor.
  3. Upload PDF files to edit.
  4. Modify the document with relevant changes.
  5. Save the PDF file.

One of the most requested features is the editing and adding text in PDF. Working with text is very convenient with C# library: edit text, update text and format text using C#. The following example demostrates how to modify a PDF document in C#:

Edit PDF Files - C#

This sample code shows how to edit text in PDF - C#

	// load PDF file
	Aspose.PDF.Document pdf  = new Aspose.PDF.Document("c:/pdftest/programaticallyproducedpdf.pdf");

	// instantiate TextFragment Absorber object
	Aspose.PDF.Text.TextFragmentAbsorber TextFragmentAbsorberAddress = new Aspose.PDF.Text.TextFragmentAbsorber();

	// search text within page bound
	TextFragmentAbsorberAddress.TextSearchOptions.LimitToPageBounds = true;

	// specify the page region for TextSearch Options
	TextFragmentAbsorberAddress.TextSearchOptions.Rectangle = new Aspose.PDF.Rectangle(100, 100, 200, 200);

	// search text from first page of PDF file
	pdf.Pages[1].Accept(TextFragmentAbsorberAddress);

	// iterate through individual TextFragment
	foreach( Aspose.PDF.Text.TextFragment tf in TextFragmentAbsorberAddress.TextFragments)
	{
		// update text to blank characters
		tf.Text = "";
	}

	// save updated PDF file after text replace
	pdf.Save("c:/pdftest/TextUpdated.pdf");

About Aspose.PDF for C# API

Aspose.PDF for C# API provides a wide range of features for working with PDF files. Some of the features include:

  • Create PDF documents from scratch or from HTML, XML, or images.
  • Edit existing PDF documents by adding or removing pages, text, images, and other content.
  • Convert PDF documents to other formats such as HTML, XML, and images.
  • Render PDF documents to images or XPS format.
  • Print PDF documents directly from your application.
  • Digitally sign PDF documents.

You can find more information on Aspose.PDF for C# API in this Aspose documentation