How to Access All PDF DOM Objects

Accessing the PDF DOM object refers to interacting with the structure of a PDF file in a way similar to manipulating a webpage's DOM (Document Object Model). In the context of PDFs, the DOM is a representation of the document’s internal structure, allowing developers to access and manipulate different elements such as text, images, annotations, and metadata programmatically.

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer

Access DOM Objects Example

The ObjectModel can be accessed from the PdfPage object. First, import the target PDF and access its Pages property. From there, select any page, and you will have access to the ObjectModel property.

CautionThis feature is still experimental.

:path=/static-assets/pdf/content-code-examples/how-to/access-pdf-dom-object.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;
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
$vbLabelText   $csharpLabel
Debug

The ObjectModel property currently consists of ImageObject, PathObject, and TextObject. Each object contains information about the page index it is on, its bounding box, scale, and translation. This information can also be modified.

ImageObject:

  • Height: Height of the image.
  • Width: Width of the image.
  • ExportBytesAsJpg: A method to export the image as a byte array in JPG format.

PathObject:

  • FillColor: The fill color of the path.
  • StrokeColor: The stroke color of the path.
  • Points: A collection of points defining the path.

TextObject:

  • Color: The color of the text.
  • Contents: The actual text content.

Ready to see what else you can do? Check out our tutorial page here: Edit PDFs

Frequently Asked Questions

How can I access PDF DOM objects in C#?

To access PDF DOM objects in C#, you can use IronPDF. Download the IronPDF library, import or render the PDF document, then access the pages collection. From there, you can use the ObjectModel property to interact with various DOM objects like text, images, and annotations.

What types of objects can I interact with in the PDF DOM?

In the PDF DOM, you can interact with objects like ImageObject, PathObject, and TextObject. These objects allow you to access and modify attributes such as size, color, and content.

How do I modify text content in a PDF using C#?

You can modify text content in a PDF by using IronPDF to access the TextObject within the ObjectModel of a PdfPage. You can then change properties like Color and Contents to update the text.

What are some common properties of the ImageObject in PDF DOM?

The ImageObject in PDF DOM includes properties like Height, Width, and methods like ExportBytesAsJpg which allow you to export the image as a byte array in JPG format.

Can I change the fill color of a path in a PDF document?

Yes, you can change the fill color of a path in a PDF document by accessing the PathObject within the PDF DOM using IronPDF, and then modifying the FillColor property.

Is accessing the PDF DOM with IronPDF fully stable?

Accessing the PDF DOM with IronPDF is currently an experimental feature and may cause memory leaks when accessing text objects, so it should be used with caution.

What is the ObjectModel in IronPDF?

The ObjectModel in IronPDF is a property of the PdfPage object that provides access to the PDF DOM, enabling interaction with PDF elements such as text, images, and paths programmatically.

How can I export images from a PDF to JPEG format?

You can export images from a PDF to JPEG format by using IronPDF to access the ImageObject in the PDF DOM and then using the ExportBytesAsJpg method to export the image as a byte array in JPEG format.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.