IRONSOFTWAREHOME
Remove PDF Objects in C#
using IronPdf;
using System.Linq;

// Load a PDF file
PdfDocument pdf = PdfDocument.FromFile("sampleObjectsWithImages.pdf");

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

// Remove first image
objects.ImageObjects.RemoveAt(0);

// Save the modified PDF
pdf.SaveAs("removed.pdf");
Imports IronPdf
Imports System.Linq

' Load a PDF file
Dim pdf As PdfDocument = PdfDocument.FromFile("sampleObjectsWithImages.pdf")

' Access DOM Objects
Dim objects = pdf.Pages.First().ObjectModel

' Remove first image
objects.ImageObjects.RemoveAt(0)

' Save the modified PDF
pdf.SaveAs("removed.pdf")
NuGet Download
PM > Install-Package IronPdf
Remove PDF Objects in C#

Remove PDF Objects in C#

Selectively removing objects from a PDF document can be a complex task. However, IronPDF provides developers with an easy and intuitive way to manipulate the PDF's Document Object Model (DOM) directly.

This example will demonstrate how to programmatically remove specific objects, such as images or text, from a PDF file using just a few lines of code.

Code Explanation

For this example, we first load a PDF file using FromFile. This method loads a PDF file of your choice and assigns it to a variable.

Afterwards, we can drill down by finding the list of objects on the first page of the PDF with Pages.First. This retrieves the first page of the PDF. To access the PDF DOM object, we then access the ObjectModel collection, which holds the PDF objects of the first page.

To remove an object, we target its specific collection within the ObjectModel. In this case, we are removing an image from the ImageObjects collection. We then call the standard list method RemoveAt and pass the index of the element we wish to delete. In this example, we remove the first image found in the collection by passing the index 0. Remember that collections are zero-indexed, so the first element is always at index zero.

Finally, we save the modified PDF, now missing the removed element, to a new file by calling SaveAs.

Discover How to Effortlessly Remove PDF DOM - Visit Our Guide Now!
View on GitHub

Ready to Get Started?

Nuget Downloads 20,878,335Version:2026.9just released

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