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.
How to Access All PDF DOM Objects
- Download the C# library to access PDF DOM Objects
- Import or render the targeted PDF document
- Access the PDF's pages collection and select the desired page
- Use the ObjectModel property to view and interact with the DOM objects
- Save or export the modified PDF document
Start using IronPDF in your project today with a free trial.
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.
:path=/static-assets/pdf/content-code-examples/how-to/access-pdf-dom-object.csusing 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
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.
Retrieving Glyph information and bounding boxes
When you need to specify exact glyphs rather than just rely on Unicode values to ensure text appears exactly as intended when combined with custom fonts and such, being able to retrieve the bounding box and glyph information is handy. IronPDF offers developers a way to retrieve such information.
We first access the ObjectModel from the PdfPage object. Afterward, we drill deeper down and access the TextObjects, which returns a collection. Finally, we call the GetGlyphInfo method to retrieve the glyph and bounding box information of the first element.
:path=/static-assets/pdf/content-code-examples/how-to/access-pdf-dom-object-retrieve-glyph.csusing IronPdf;
using System.Linq;
PdfDocument pdf = PdfDocument.FromFile("invoice.pdf");
var glyph = pdf.Pages.First().ObjectModel.TextObjects.First().GetGlyphInfo();IRON VB CONVERTER ERROR developers@ironsoftware.com
Translate PDF Object
There are times when you need to adjust a PDF's layout by repositioning elements, such as text or images. You can easily move an object to a new spot on the page by changing its Translate property.
The code example below renders an HTML string that uses CSS Flexbox to center text in the middle of the PDF. Then, we access the first TextObject, which is the word "Centered."
Finally, we translate the TextObject by assigning a new PointF to its Translate property. This shifts the text 200 points to the right and 150 points up and saves the modified PDF.
Code Example
:path=/static-assets/pdf/content-code-examples/how-to/access-pdf-dom-object-translate.csusing IronPdf;
using System.Drawing;
using System.Linq;
// Setup the Renderer
var renderer = new ChromePdfRenderer();
// We use CSS Flexbox to perfectly center the text vertically and horizontally.
var html = @"
<div style='display: flex; justify-content: center; align-items: center; font-size: 48px;'>
Centered
</div>";
// Render the HTML to a PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);
// Save the original PDF to see the "before" state
pdf.SaveAs("BeforeTranslate.pdf");
// Access the first text object on the first page
// In this simple HTML, this will be our "Centered" text block.
var textObject = pdf.Pages.First().ObjectModel.TextObjects.First();
// Apply the translation
// This moves the object 200 points to the right and 150 points up from its original position.
textObject.Translate = new PointF(200, 150);
// Save the modified PDF to see the "after" state
pdf.SaveAs("AfterTranslate.pdf");IRON VB CONVERTER ERROR developers@ironsoftware.comOutput
As you can see in the output, the word "Centered" has shifted 200 points to the right and 150 points up from its original position.

Scale PDF Object
You can resize any PDF object, such as text or an image, using the Scale property. This property acts as a multiplier. A factor greater than 1 increases the object's size, while a factor between 0 and 1 decreases it.
In this example, we render an HTML string containing an image. Then, we access the first ImageObject and scale it to 70% of its original size. We do this by assigning its Scale property a new PointF with a value of 0.7 for both axes. Finally, we save the modified PDF.
Code Example
:path=/static-assets/pdf/content-code-examples/how-to/access-pdf-dom-object-scale.csusing IronPdf;
using System.Drawing;
using System.Linq;
// Setup the Renderer
var renderer = new ChromePdfRenderer();
// The image is placed in a div to give it some space on the page.
string html = @"<img src='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTi8LuOR6_A98euPLs-JRwoLU7Nc31nVP15rw&s'>";
// Render the HTML to a PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);
// Save the PDF before scaling for comparison
pdf.SaveAs("BeforeScale.pdf");
// Access the first image object on the first page
var image = pdf.Pages.First().ObjectModel.ImageObjects.First();
// We scale the image to 70% of its original size on both the X and Y axes.
image.Scale = new PointF(0.7f, 0.7f);
// Save the modified PDF to see the result
pdf.SaveAs("AfterScale.pdf");IRON VB CONVERTER ERROR developers@ironsoftware.comOutput
The output shows the image scaled to 70% of its original size.

Remove PDF Object
You can clean up a PDF by completely removing objects, such as text blocks, shapes, or images. The process involves accessing the PDF DOM collection of objects, such as ImageObjects or TextObjects, and removing an item from that collection. You can remove an object by calling the RemoveAt method on the collection and passing the index of the object you want to delete.
In the following code, we load the BeforeScale.pdf file created in the previous example and remove the first image from the first page.
:path=/static-assets/pdf/content-code-examples/how-to/access-pdf-dom-object-remove.csusing IronPdf;
using IronSoftware.Pdfium.Dom;
using System.Linq;
// Load the PDF file we created in the Scale example
PdfDocument pdf = PdfDocument.FromFile("BeforeScale.pdf");
// Access DOM Objects
IPdfPageObjectModel objects = pdf.Pages.First().ObjectModel;
// Remove first image
objects.ImageObjects.RemoveAt(0);
// Save the modified PDF
pdf.SaveAs("removedFirstImage.pdf");IRON VB CONVERTER ERROR developers@ironsoftware.comReady 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.




