# How to Edit PDFs in C#
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 smooth 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#.
*as-heading:2(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.
```cs
:title=Edit PDFs Instantly with IronPDF
var pdf = IronPdf.PdfDocument.FromFile("example.pdf");
pdf.ApplyStamp(new IronPdf.Editing.TextStamper("Confidential"));
pdf.SaveAs("edited_example.pdf");
```
*as-heading:2(Table of Contents)*
- **Edit Document Structure**
- [Access PDF DOM Object](#anchor-access-pdf-dom-object)
- [Work with PDF Layers](#anchor-work-with-pdf-layers)
- [Save & Export PDF Documents](#anchor-save-export-documents)
- [Load PDFs from Memory](#anchor-load-pdfs-from-memory)
- [Export PDFs to Memory](#anchor-export-pdfs-to-memory)
- **Edit Document Properties**
- [Parse PDFs in C#](#anchor-parse-pdfs-in-c)
- [Extract Text & Images](#anchor-extract-text-images)
- [Redact Text & Regions](#anchor-redact-texts-regions)
- [Replace Text in PDF](#anchor-replace-text-in-pdf)
- **Enhance PDF Design**
- [Add & Edit Annotations](#anchor-add-edit-annotations)
- [Stamp Text & Images](#anchor-stamp-text-images)
- [Custom Watermarks](#anchor-custom-watermarks)
- [Backgrounds & Foregrounds](#anchor-backgrounds-foregorunds)
- [Draw Text & Bitmap](#anchor-draw-text-bitmap)
- [Draw Line & Rectangle](#anchor-draw-line-rectangle)
- [Rotate Text and Pages](#anchor-rotate-text-and-pages)
- [Transform PDF Pages](#anchor-transform-pdf-pages)
## 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.
```cs
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](https://ironpdf.com/how-to/access-pdf-dom-object/).
### 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.
```cs
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);
}
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/access-pdf-dom-object/).
### 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](https://ironpdf.com/how-to/export-save-pdf-csharp/).
### Load PDFs from Memory
IronPDF perfectly integrates with existing C# .NET applications; we can load and create PDF files from `MemoryStream`s through the `MemoryStream` object.
```cs
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](https://ironpdf.com/how-to/pdf-memory-stream/).
### Export PDFs to Memory
Similarly, we can also export PDFs to `MemoryStream` in C# .NET through the `MemoryStream` object.
```cs
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](https://ironpdf.com/how-to/pdf-to-memory-stream/).
## 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 simplifies your workflow!
```cs
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](https://ironpdf.com/how-to/csharp-parse-pdf/).
### 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.
```cs
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](https://ironpdf.com/how-to/extract-text-and-images/).
### 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.
```cs
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](https://ironpdf.com/how-to/redact-text/).
### 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.
```cs
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](https://ironpdf.com/how-to/find-replace-text/).
## 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.
```cs
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](https://ironpdf.com/how-to/annotations/).
### 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.
```cs
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](https://ironpdf.com/how-to/stamp-text-image/).
### Custom Watermarks
We can also employ the `ApplyWatermark` method to 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.
```cs
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](https://ironpdf.com/how-to/custom-watermark/).
### Backgrounds & Foregrounds
In addition to watermarks and stamps, we can also add a background to customize your PDF using `AddBackgroundPdf` entirely.
```cs
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](https://ironpdf.com/how-to/background-foreground/).
### 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.
```cs
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](https://ironpdf.com/how-to/draw-text-and-bitmap/).
### 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.
```cs
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](https://ironpdf.com/how-to/draw-line-and-rectangle/).
### 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.
```cs
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](https://ironpdf.com/object-reference/api/IronPdf.Rendering.PdfPageRotation.html).
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/rotating-text/).
### 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.
```cs
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](https://ironpdf.com/how-to/transform-pdf-pages/).
## 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](/troubleshooting/engineering-request-pdf/). We will be more than happy to assist you.
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 smooth 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.
1Install IronPDF with NuGet Package Manager
PM > Install-Package IronPdf
Install-Package IronPdf
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");
var pdf = IronPdf.PdfDocument.FromFile("example.pdf");
pdf.ApplyStamp(new IronPdf.Editing.TextStamper("Confidential"));
pdf.SaveAs("edited_example.pdf");
Dim pdf = IronPdf.PdfDocument.FromFile("example.pdf")pdf.ApplyStamp(New IronPdf.Editing.TextStamper("Confidential"))pdf.SaveAs("edited_example.pdf")
Dim pdf = IronPdf.PdfDocument.FromFile("example.pdf")
pdf.ApplyStamp(New IronPdf.Editing.TextStamper("Confidential"))
pdf.SaveAs("edited_example.pdf")
3Deploy to test on your live environment
Start using IronPDF in your project today with a free trial
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 RendererChromePdfRenderer renderer = new ChromePdfRenderer();// Create a PDF from a URLPdfDocument pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");// Access DOM Objectsvar objects = pdf.Pages.First().ObjectModel;
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;
ImportsIronPdfImportsSystem.Linq' Instantiate RendererPrivate renderer As New ChromePdfRenderer()' Create a PDF from a URLPrivate pdf AsPdfDocument = renderer.RenderUrlAsPdf("https://ironpdf.com/")' Access DOM ObjectsPrivate objects = pdf.Pages.First().ObjectModel
Imports IronPdf
Imports System.Linq
' Instantiate Renderer
Private renderer As New ChromePdfRenderer()
' Create a PDF from a URL
Private pdf As PdfDocument = renderer.RenderUrlAsPdf("https://ironpdf.com/")
' Access DOM Objects
Private 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 exportusing PdfDocument pdf = new PdfDocument("blueprint.pdf");// Enumerate every Optional Content Group (OCG) layer in the documentConsole.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 textPdfLayer titleBlock = pdf.Layers.FindByName("Title Block");if (titleBlock != null){ string headerText = pdf.ExtractTextFromLayer(titleBlock.Id);Console.WriteLine(headerText);}
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);
}
ImportsIronPdfImportsIronSoftwareImportsSystem' Load a layered PDF, such as a CAD plan, engineering drawing, or map exportUsing pdf As New PdfDocument("blueprint.pdf") ' Enumerate every Optional Content Group (OCG) layer in the documentConsole.WriteLine($"Document has {pdf.Layers.Count} layers") For Each layer AsPdfLayerIn pdf.LayersConsole.WriteLine($" {layer.Id}: ""{layer.Name}"" visible={layer.IsVisible} parent={layer.ParentId}") Next ' Look a layer up by name (case-sensitive) and extract just its text Dim titleBlock AsPdfLayer = pdf.Layers.FindByName("Title Block") If titleBlock IsNot Nothing Then Dim headerText AsString = pdf.ExtractTextFromLayer(titleBlock.Id)Console.WriteLine(headerText) End IfEndUsing
Imports IronPdf
Imports IronSoftware
Imports System
' Load a layered PDF, such as a CAD plan, engineering drawing, or map export
Using pdf As New PdfDocument("blueprint.pdf")
' Enumerate every Optional Content Group (OCG) layer in the document
Console.WriteLine($"Document has {pdf.Layers.Count} layers")
For Each layer As PdfLayer In pdf.Layers
Console.WriteLine($" {layer.Id}: ""{layer.Name}"" visible={layer.IsVisible} parent={layer.ParentId}")
Next
' Look a layer up by name (case-sensitive) and extract just its text
Dim titleBlock As PdfLayer = pdf.Layers.FindByName("Title Block")
If titleBlock IsNot Nothing Then
Dim headerText As String = pdf.ExtractTextFromLayer(titleBlock.Id)
Console.WriteLine(headerText)
End If
End Using
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 streamvar fileByte = File.ReadAllBytes("sample.pdf");// Instantiate PDF object from streamPdfDocument pdf = new PdfDocument(fileByte);
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);
ImportsIronPdfImportsSystem.IO' Read PDF file as streamPrivate fileByte = File.ReadAllBytes("sample.pdf")' Instantiate PDF object from streamPrivate pdf As New PdfDocument(fileByte)
Imports IronPdf
Imports System.IO
' Read PDF file as stream
Private fileByte = File.ReadAllBytes("sample.pdf")
' Instantiate PDF object from stream
Private pdf As 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 PDFPdfDocument pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");// Export PDF as StreamMemoryStream pdfAsStream = pdf.Stream;// Export PDF as Byte Arraybyte[] pdfAsByte = pdf.BinaryData;
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;
ImportsIronPdfImportsSystem.IOPrivate renderer = New ChromePdfRenderer()' Convert the URL into PDFPrivate pdf AsPdfDocument = renderer.RenderUrlAsPdf("https://ironpdf.com/")' Export PDF as StreamPrivate pdfAsStream AsMemoryStream = pdf.Stream' Export PDF as Byte ArrayPrivate pdfAsByte() AsByte = pdf.BinaryData
Imports IronPdf
Imports System.IO
Private renderer = New ChromePdfRenderer()
' Convert the URL into PDF
Private pdf As PdfDocument = renderer.RenderUrlAsPdf("https://ironpdf.com/")
' Export PDF as Stream
Private pdfAsStream As MemoryStream = pdf.Stream
' Export PDF as Byte Array
Private pdfAsByte() As Byte = 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 simplifies your workflow!
using IronPdf;// Select the desired PDF FilePdfDocument pdf = PdfDocument.FromFile("sample.pdf");// Extract all text from an pdfstring allText = pdf.ExtractAllText();// Extract all text from page 1string page1Text = pdf.ExtractTextFromPage(0);
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);
ImportsIronPdf' Select the desired PDF FilePrivate pdf AsPdfDocument = PdfDocument.FromFile("sample.pdf")' Extract all text from an pdfPrivate allText AsString = pdf.ExtractAllText()' Extract all text from page 1Private page1Text AsString = pdf.ExtractTextFromPage(0)
Imports IronPdf
' Select the desired PDF File
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Extract all text from an pdf
Private allText As String = pdf.ExtractAllText()
' Extract all text from page 1
Private page1Text As String = 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 imagesvar images = pdf.ExtractAllImages();for(int i = 0; i < images.Count; i++){ // Export the extracted images images[i].SaveAs($"images/image{i}.png");}
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");
}
ImportsIronPdfPrivate pdf AsPdfDocument = PdfDocument.FromFile("sample.pdf")' Extract imagesPrivate images = pdf.ExtractAllImages()For i AsInteger = 0 To images.Count - 1 ' Export the extracted images images(i).SaveAs($"images/image{i}.png")Next i
Imports IronPdf
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Extract images
Private images = pdf.ExtractAllImages()
For i As Integer = 0 To images.Count - 1
' Export the extracted images
images(i).SaveAs($"images/image{i}.png")
Next i
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 pagespdf.RedactTextOnAllPages("Alaric");pdf.SaveAs("redacted.pdf");
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("novel.pdf");
// Redact 'Alaric' phrase from all pages
pdf.RedactTextOnAllPages("Alaric");
pdf.SaveAs("redacted.pdf");
ImportsIronPdfPrivate pdf AsPdfDocument = PdfDocument.FromFile("novel.pdf")' Redact 'Alaric' phrase from all pagespdf.RedactTextOnAllPages("Alaric")pdf.SaveAs("redacted.pdf")
Imports IronPdf
Private pdf As PdfDocument = 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 pagespdf.ReplaceTextOnAllPages(oldText, newText);pdf.SaveAs("replaceText.pdf");
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");
ImportsIronPdfPrivate renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>.NET6</h1>")Private oldText AsString = ".NET6"Private newText AsString = ".NET7"' Replace text on all pagespdf.ReplaceTextOnAllPages(oldText, newText)pdf.SaveAs("replaceText.pdf")
Imports IronPdf
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>.NET6</h1>")
Private oldText As String = ".NET6"
Private newText As String = ".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.
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.
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 indexTextAnnotation annotation = new TextAnnotation(0){Title = "This is the title",Contents = "This is the long 'sticky note' comment content...",X = 50,Y = 700,};// Add the annotationpdf.Annotations.Add(annotation);pdf.SaveAs("annotation.pdf");
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");
ImportsIronPdfImportsIronPdf.AnnotationsDim renderer As New ChromePdfRenderer()Dim pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Annotation</h1>")' Create a PDF annotation object on a specified page indexDim annotation As New TextAnnotation(0) With { .Title = "This is the title", .Contents = "This is the long 'sticky note' comment content...", .X = 50, .Y = 700}' Add the annotationpdf.Annotations.Add(annotation)pdf.SaveAs("annotation.pdf")
Imports IronPdf
Imports IronPdf.Annotations
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Annotation</h1>")
' Create a PDF annotation object on a specified page index
Dim annotation As New TextAnnotation(0) With {
.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 stamperTextStamper textStamper = new TextStamper(){Text = "Text Stamper!",FontFamily = "Bungee Spice",UseGoogleFont = true,FontSize = 30,IsBold = true,IsItalic = true,VerticalAlignment = VerticalAlignment.Top,};// Stamp the text stamperpdf.ApplyStamp(textStamper);pdf.SaveAs("stampText.pdf");
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");
ImportsIronPdfImportsIronPdf.EditingPrivate renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")' Create text stamperPrivate textStamper As New TextStamper() With { .Text = "Text Stamper!", .FontFamily = "Bungee Spice", .UseGoogleFont = True, .FontSize = 30, .IsBold = True, .IsItalic = True, .VerticalAlignment = VerticalAlignment.Top}' Stamp the text stamperpdf.ApplyStamp(textStamper)pdf.SaveAs("stampText.pdf")
Imports IronPdf
Imports IronPdf.Editing
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")
' Create text stamper
Private textStamper As New TextStamper() With {
.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 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 watermarkpdf.ApplyWatermark(watermarkHtml);pdf.SaveAs("watermark.pdf");
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");
ImportsIronPdfPrivate watermarkHtml AsString = "<img src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'><h1>Iron Software</h1>"Private renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Watermark</h1>")' Apply watermarkpdf.ApplyWatermark(watermarkHtml)pdf.SaveAs("watermark.pdf")
Imports IronPdf
Private watermarkHtml As String = "
<img src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1>Iron Software</h1>"
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = 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 backgroundPdfDocument background = renderer.RenderHtmlAsPdf("<body style='background-color: cyan;'></body>");// Add backgroundpdf.AddBackgroundPdf(background);pdf.SaveAs("addBackground.pdf");
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");
ImportsIronPdfPrivate renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Main HTML content</h1>")' Render backgroundPrivate background AsPdfDocument = renderer.RenderHtmlAsPdf("<body style='background-color: cyan;'></body>")' Add backgroundpdf.AddBackgroundPdf(background)pdf.SaveAs("addBackground.pdf")
Imports IronPdf
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Main HTML content</h1>")
' Render background
Private background As PdfDocument = 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 PDFpdf.DrawText("Some text", FontTypes.TimesNewRoman.Name, FontSize: 12, PageIndex: 0, X: 100, Y: 100, Color.Black, Rotation: 0);pdf.SaveAs("drawText.pdf");
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");
ImportsIronPdfImportsIronSoftware.DrawingDim renderer As New ChromePdfRenderer()Dim pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>testing</h1>")' Draw text on PDFpdf.DrawText("Some text", FontTypes.TimesNewRoman.Name, FontSize:=12, PageIndex:=0, X:=100, Y:=100, Color.Black, Rotation:=0)pdf.SaveAs("drawText.pdf")
Imports IronPdf
Imports IronSoftware.Drawing
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = 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 parametersint 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 PDFpdf.DrawLine(pageIndex, start, end, width, color);pdf.SaveAs("drawLine.pdf");
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");
ImportsIronPdfPrivate renderer As New ChromePdfRenderer()Private pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>testing</h1>")' Configure the required parametersPrivate pageIndex AsInteger = 0Private start = New IronSoftware.Drawing.PointF(200,150)Private [end] = New IronSoftware.Drawing.PointF(1000,150)Private width AsInteger = 10Private color = New IronSoftware.Drawing.Color("#000000")' Draw line on PDFpdf.DrawLine(pageIndex, start, [end], width, color)pdf.SaveAs("drawLine.pdf")
Imports IronPdf
Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>testing</h1>")
' Configure the required parameters
Private pageIndex As Integer = 0
Private start = New IronSoftware.Drawing.PointF(200,150)
Private [end] = New IronSoftware.Drawing.PointF(1000,150)
Private width As Integer = 10
Private 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 PDFPdfDocument pdf = PdfDocument.FromFile("multi-page.pdf");// Set rotation for a single pagepdf.SetPageRotation(0, PdfPageRotation.Clockwise90);// Set rotation for multiple pagespdf.SetPageRotations(Enumerable.Range(1,3), PdfPageRotation.Clockwise270);// Set rotation for the entire documentpdf.SetAllPageRotations(PdfPageRotation.Clockwise180);pdf.SaveAs("rotated.pdf");
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");
ImportsIronPdfImportsIronPdf.RenderingImportsSystem.Linq' Import PDFPrivate pdf AsPdfDocument = PdfDocument.FromFile("multi-page.pdf")' Set rotation for a single pagepdf.SetPageRotation(0, PdfPageRotation.Clockwise90)' Set rotation for multiple pagespdf.SetPageRotations(Enumerable.Range(1,3), PdfPageRotation.Clockwise270)' Set rotation for the entire documentpdf.SetAllPageRotations(PdfPageRotation.Clockwise180)pdf.SaveAs("rotated.pdf")
Imports IronPdf
Imports IronPdf.Rendering
Imports System.Linq
' Import PDF
Private pdf As PdfDocument = 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");
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("basic.pdf");
pdf.Pages[0].Transform(50, 50, 0.8, 0.8);
pdf.SaveAs("transformPage.pdf");
ImportsIronPdfDim pdf AsPdfDocument = PdfDocument.FromFile("basic.pdf")pdf.Pages(0).Transform(50, 50, 0.8, 0.8)pdf.SaveAs("transformPage.pdf")
Imports IronPdf
Dim pdf As PdfDocument = 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 straightforward 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 integrate into existing C# .NET applications, with features that allow loading and creating PDFs directly from streams, supporting reliable 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 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.