IRONSOFTWAREHOME

How to Edit PDFs in C#

Curtis Chau
Curtis Chau
Updated: August 2, 2026

Iron Software has simplified various PDF editing functions into easy-to-understand methods in the IronPDF library. Be it adding signatures, adding HTML footers, stamping watermarks, or adding annotations. IronPDF is the tool for you, allowing you to have readable code, programmatic PDF generation, easy debugging, and seamless deployment to any supported environment or platform.

IronPDF boasts numerous features for editing PDFs. In this tutorial article, we will walk through some of the major ones, providing code examples and explanations.

With this article, you will have a good understanding of how to use IronPDF to edit your PDFs in C#.

Quickstart: Edit Your PDF Files in Seconds

Effortlessly edit PDF documents in C# with IronPDF. This quick guide shows you how to add a text stamp to an existing PDF file. With just a few lines of code, you can modify your PDF and save the changes instantly. Perfect for developers needing a fast and efficient PDF editing solution.

  1. 1Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. 2Copy and run this code snippet.

    var pdf = IronPdf.PdfDocument.FromFile("example.pdf");
    pdf.ApplyStamp(new IronPdf.Editing.TextStamper("Confidential"));
    pdf.SaveAs("edited_example.pdf");
    C#
  3. 3Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer
Table of Contents

Edit Document Structure

Access PDF DOM Object

Manipulating and accessing the PDF objects is quick and straightforward. IronPDF simplifies how developers interact with DOM Objects by making them familiar with how to manipulate a web page's DOM, allowing developers to access and manipulate various elements, such as text, programmatically.

using IronPdf;
using System.Linq;

// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Create a PDF from a URL
PdfDocument pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");

// Access DOM Objects
var objects = pdf.Pages.First().ObjectModel;

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Work with PDF Layers

Layered PDFs (CAD plans, engineering drawings, and map exports) keep their content in named Optional Content Groups. IronPDF exposes them through PdfDocument.Layers, so you can enumerate the layers, find one by name, and extract the text scoped to it.

using IronPdf;
using IronSoftware;
using System;

// Load a layered PDF, such as a CAD plan, engineering drawing, or map export
using PdfDocument pdf = new PdfDocument("blueprint.pdf");

// Enumerate every Optional Content Group (OCG) layer in the document
Console.WriteLine($"Document has {pdf.Layers.Count} layers");
foreach (PdfLayer layer in pdf.Layers)
{
    Console.WriteLine($"  {layer.Id}: \"{layer.Name}\"  visible={layer.IsVisible}  parent={layer.ParentId}");
}

// Look a layer up by name (case-sensitive) and extract just its text
PdfLayer titleBlock = pdf.Layers.FindByName("Title Block");
if (titleBlock != null)
{
    string headerText = pdf.ExtractTextFromLayer(titleBlock.Id);
    Console.WriteLine(headerText);
}
C#

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Save & Export Documents

To save and export documents, IronPDF allows users to quickly save the edited document PdfDocument.SaveAs to the disk while also allowing exports to other formats, such as Binary Data and Memory Streams.

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Load PDFs from Memory

IronPDF perfectly integrates with existing C# .NET applications; we can load and create PDF files from MemoryStreams through the MemoryStream object.

using IronPdf;
using System.IO;

// Read PDF file as stream
var fileByte = File.ReadAllBytes("sample.pdf");

// Instantiate PDF object from stream
PdfDocument pdf = new PdfDocument(fileByte);

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Export PDFs to Memory

Similarly, we can also export PDFs to MemoryStream in C# .NET through the MemoryStream object.

using IronPdf;
using System.IO;

var renderer = new ChromePdfRenderer();

// Convert the URL into PDF
PdfDocument pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");

// Export PDF as Stream
MemoryStream pdfAsStream = pdf.Stream;

// Export PDF as Byte Array
byte[] pdfAsByte = pdf.BinaryData;

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Edit Document Text

Parse PDFs in C#

Extracting text from a PDF is quick and easy with IronPDF. Just use the ExtractAllText method to pull all the text from every page, allowing you to access and utilize your document's content effortlessly. This powerful feature enhances productivity and streamlines your workflow!

using IronPdf;

// Select the desired PDF File
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");

// Extract all text from an pdf
string allText = pdf.ExtractAllText();

// Extract all text from page 1
string page1Text = pdf.ExtractTextFromPage(0);

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Extract Text & Images

With IronPDF, you’re not just limited to extracting text; it's also incredibly easy to pull images out of your PDFs! With the ExtractAllImages feature, you can swiftly capture all the visuals you need.

using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("sample.pdf");

// Extract images
var images = pdf.ExtractAllImages();

for(int i = 0; i < images.Count; i++)
{
    // Export the extracted images
    images[i].SaveAs($"images/image{i}.png");
}

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Redact Texts & Regions

In scenarios where we need to safeguard sensitive information by redacting it, we have a powerful tool at our fingertips: RedactTextOnAllPages. With this feature, we can effortlessly identify and conceal every instance of a specific keyword throughout the entire PDF. It's an efficient way to ensure that confidential details remain protected while still allowing us to share the document with confidence.

using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("novel.pdf");

// Redact 'Alaric' phrase from all pages
pdf.RedactTextOnAllPages("Alaric");

pdf.SaveAs("redacted.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Replace Text in PDF

To enhance your PDF documents using IronPDF, you can easily replace text throughout the entire file. By utilizing the ReplaceTextOnAllPages function, you can provide the oldText that needs to be replaced along with the newText that will serve as its substitute. This method efficiently updates all instances of the oldText across the document, ensuring a consistent and professional appearance.

using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>.NET6</h1>");

string oldText = ".NET6";
string newText = ".NET7";

// Replace text on all pages
pdf.ReplaceTextOnAllPages(oldText, newText);

pdf.SaveAs("replaceText.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

My favorite library of this kind is IronPDF. It allows for fast and efficient manipulation of PDF files. It also has many valuable features, like exporting to PDF/A format and digitally signing PDF documents.

Milan Jovanovic

Microsoft MVP

View case study

IronOCR means we can save $40,000 annually from manual processing, while enhancing productivity and freeing up resources for high-impact tasks. I would highly recommend it.

Brent Matzelle

Chief Technology Officer, OPYN

View case study

The IronSuite play a crucial role in our operations. These are tools that increase efficiencies across the business including creating floor plans and improving inventory management.

David Jones

Lead Software Engineer, Agorus Build

View case study

Enhance PDF Design

Add & Edit Annotations

IronPDF offers extensive customization options for PDF annotations, allowing users to add "sticky note" style comments directly to PDF pages. Through the TextAnnotation class, annotations can be added programmatically, featuring advanced options such as sizing, opacity, icon selection, and editing capabilities. The LinkAnnotation class adds clickable internal navigation links, such as custom tables of contents and back-to-top buttons, through the same annotations collection.

using IronPdf;
using IronPdf.Annotations;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Annotation</h1>");

// Create a PDF annotation object on a specified page index
TextAnnotation annotation = new TextAnnotation(0)
{
    Title = "This is the title",
    Contents = "This is the long 'sticky note' comment content...",
    X = 50,
    Y = 700,
};

// Add the annotation
pdf.Annotations.Add(annotation);
pdf.SaveAs("annotation.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Stamp Text & Images

IronPDF provides extensive options for customizing how to stamp text and images onto a PDF. In this example, we'll use the TextStamper class to apply a stamp to the PDF using the ApplyStamp method, as shown below.

using IronPdf;
using IronPdf.Editing;

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");

// Create text stamper
TextStamper textStamper = new TextStamper()
{
    Text = "Text Stamper!",
    FontFamily = "Bungee Spice",
    UseGoogleFont = true,
    FontSize = 30,
    IsBold = true,
    IsItalic = true,
    VerticalAlignment = VerticalAlignment.Top,
};

// Stamp the text stamper
pdf.ApplyStamp(textStamper);

pdf.SaveAs("stampText.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Custom Watermarks

We can also employ the ApplyWatermark method to seamlessly integrate a watermark into both newly rendered PDFs and existing documents. This functionality enables enhanced brand recognition, ensuring that your materials convey a professional image.

using IronPdf;

string watermarkHtml = @"
<img src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1>Iron Software</h1>";

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Watermark</h1>");

// Apply watermark
pdf.ApplyWatermark(watermarkHtml);

pdf.SaveAs("watermark.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Backgrounds & Foregrounds

In addition to watermarks and stamps, we can also add a background to customize your PDF using AddBackgroundPdf entirely.

using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Main HTML content</h1>");

// Render background
PdfDocument background = renderer.RenderHtmlAsPdf("<body style='background-color: cyan;'></body>");

// Add background
pdf.AddBackgroundPdf(background);

pdf.SaveAs("addBackground.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Draw Text & Bitmap

Drawing text on PDFs is intuitive and straightforward; we use DrawText and provide it with the necessary parameters. In this example, we are adding the new phrase Some text with the font Times New Roman.

using IronPdf;
using IronSoftware.Drawing;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>testing</h1>");

// Draw text on PDF
pdf.DrawText("Some text", FontTypes.TimesNewRoman.Name, FontSize: 12, PageIndex: 0, X: 100, Y: 100, Color.Black, Rotation: 0);

pdf.SaveAs("drawText.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Draw Line & Rectangle

IronPDF also supports drawing lines on the PDF. We first create the start and end points by initializing two PointF classes, then apply them with the DrawLine method, as shown below.

using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>testing</h1>");

// Configure the required parameters
int pageIndex = 0;
var start = new IronSoftware.Drawing.PointF(200,150);
var end = new IronSoftware.Drawing.PointF(1000,150);
int width = 10;
var color = new IronSoftware.Drawing.Color("#000000");

// Draw line on PDF
pdf.DrawLine(pageIndex, start, end, width, color);

pdf.SaveAs("drawLine.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Rotate Text and Pages

To rotate the PDF pages, we can use the SetPageRotation method to rotate specific pages. In the example below, we are only rotating pages 2 to 4, leaving page 1 unchanged to showcase the capabilities.

using IronPdf;
using IronPdf.Rendering;
using System.Linq;

// Import PDF
PdfDocument pdf = PdfDocument.FromFile("multi-page.pdf");

// Set rotation for a single page
pdf.SetPageRotation(0, PdfPageRotation.Clockwise90);

// Set rotation for multiple pages
pdf.SetPageRotations(Enumerable.Range(1,3), PdfPageRotation.Clockwise270);

// Set rotation for the entire document
pdf.SetAllPageRotations(PdfPageRotation.Clockwise180);

pdf.SaveAs("rotated.pdf");

For a list of available enums regarding the rotation angle, please refer to here.

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Transform PDF Pages

Aside from rotations, we can also transform the pdf pages by providing a range of parameters. In the example below, we select the first page of the PDF and, using Transform, move the contents of the first page 50 points to the right and down and scale it to 80% of its original size.

using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("basic.pdf");

pdf.Pages[0].Transform(50, 50, 0.8, 0.8);

pdf.SaveAs("transformPage.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Conclusion

The list of examples above demonstrates that IronPDF has key features that work out of the box when it comes to editing PDFs.

If you would like to make a feature request or have any general questions about IronPDF or licensing, please contact our support team. We will be more than happy to assist you.

Frequently Asked Questions

How can I add a text stamp to a PDF using IronPDF?

You can add a text stamp using the `TextStamper` class in IronPDF. Instantiate a `PdfDocument` object, apply the stamp with the `ApplyStamp` method, and save the changes. This allows you to efficiently modify PDF files programmatically.

What method does IronPDF offer for extracting images from a PDF?

IronPDF provides the `ExtractAllImages` method. This feature allows you to easily pull out and save all images from a PDF, simplifying the process of extracting and managing visual content.

Can IronPDF handle text redaction in PDFs?

Yes, using the `RedactTextOnAllPages` function, IronPDF can redact specific phrases or keywords across all pages of a PDF, ensuring sensitive information is concealed consistently throughout your document.

Does IronPDF support rotating pages within a PDF?

IronPDF allows for page rotation using methods like `SetPageRotation` or `SetAllPageRotations`, enabling you to rotate specific pages or the entire document to various angles programmatically.

How do you export a PDF to a memory stream using IronPDF?

You can export a PDF to a memory stream in IronPDF by creating a `MemoryStream` object and using the `PdfDocument.Stream` method for exporting, allowing seamless integration with other parts of your application.

What options does IronPDF provide for annotating PDFs?

IronPDF supports extensive annotation capabilities, including `TextAnnotation` and `LinkAnnotation` classes for adding sticky notes and interactive navigation links, enhancing PDF interactivity and user engagement.

How can custom watermarks be added to PDFs using IronPDF?

With the `ApplyWatermark` method in IronPDF, you can add HTML-based watermarks to both new and existing PDFs, facilitating brand recognition and professional presentation of your documents.

Is it possible to replace text in a PDF using IronPDF?

Yes, IronPDF's `ReplaceTextOnAllPages` function allows you to substitute text throughout a document, making it simple to update repeated content efficiently.

Can IronPDF integrate PDF generation into existing C# applications?

IronPDF can seamlessly integrate into existing C# .NET applications, with features that allow loading and creating PDFs directly from streams, supporting robust application development.

What capabilities does IronPDF offer for transforming PDF page content?

IronPDF provides `Transform` methods for translating and scaling PDF page content, allowing precise manipulation and customization of document presentations programmatically.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 20,809,720Version:2026.9just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required