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

// Create a PDF from a URL using a PNG image
string html = @"<img src='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTi8LuOR6_A98euPLs-JRwoLU7Nc31nVP15rw&s'>";
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render HTML to PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);

// Access the first image object on the first page
var image = pdf.Pages.First().ObjectModel.ImageObjects.First();

// To scale the image to 70% of its original size uniformly
image.Scale = new System.Drawing.PointF(0.7f, 0.7f);

// Save the PDF with the scaled image
pdf.SaveAs("scaled_image.pdf");
Imports IronPdf
Imports System.Linq

' Create a PDF from a URL using a PNG image
Dim html As String = "<img src='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTi8LuOR6_A98euPLs-JRwoLU7Nc31nVP15rw&s'>"
Dim renderer As New ChromePdfRenderer()
' Render HTML to PDF
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(html)

' Access the first image object on the first page
Dim image = pdf.Pages.First().ObjectModel.ImageObjects.First()

' To scale the image to 70% of its original size uniformly
image.Scale = New System.Drawing.PointF(0.7F, 0.7F)

' Save the PDF with the scaled image
pdf.SaveAs("scaled_image.pdf")
NuGet Download
PM > Install-Package IronPdf
Scale PDF Objects in C#

Scale PDF Objects in C#

IronPDF empowers developers to programmatically scale PDF objects, allowing for precise control over elements such as text and images within a PDF, without requiring modifications to the original file or the creation of an entirely new one.

Using the IronPDF library, you can easily scale PDF objects. The example below demonstrates how to accomplish this task with just a few lines of code.

Code Explanation

For this example, we first create an HTML string that includes an &lt;img&gt; tag to embed an image. Afterwards, using the RenderHtmlAsPdf method, we render that HTML string into a PdfDocument object.

To access the ImageObject that we just added, we navigate through the document's structure. We first access the PDF's initial page using Pages.First. From there, we drill down into its ObjectModel, which contains the structured content of the page. We then access the ImageObjects collection, retrieve the first element, and assign it to a variable.

To scale the image, we assign a new PointF to the Scale property. In this example, we are scaling the image to 70% of its original size along both the x and y axes. Note that scaling by a factor greater than one increases the size, while a factor smaller than one (but greater than zero) effectively shrinks the image. You could also scale non-uniformly by providing different values for x and y.

After modifying the Scale property, we finally call the SaveAs method to save the PDF with the applied changes.

Discover How to Effortlessly Scale 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