iTextSharp: Add Image to PDF
IronPDF offers simpler image addition with fewer lines of code and a perpetual license, while iTextSharp provides more granular control but requires more code and has complex licensing under AGPL for commercial use.
When working with PDF files in a .NET environment, adding images to documents is a common requirement for many applications. Whether you're generating invoices with company logos, creating reports with embedded charts, or producing custom documents with watermarks, the ability to embed images into PDFs is essential. Two popular PDF libraries in C# are IronPDF and iTextSharp. This article compares both libraries on their ability to add images to PDFs, considering ease of use, performance, licensing models, and advanced features like image compression and format support.
What Are the Key Differences Between IronPDF and iTextSharp?
What Image Features Does Each Library Offer?
IronPDF: IronPDF simplifies adding images to PDFs with built-in support for both local and remote images from URLs. Its API provides control over position, width, and scaling. The library supports JPEG, PNG, GIF, SVG, and WebGL content. The stamping functionality provides methods for watermarking, letterheads, and overlaying images. The Chrome rendering engine ensures accurate rendering of complex graphics and responsive images.
iTextSharp: iTextSharp offers image embedding through its lower-level API. It provides a flexible interface handling JPG and PNG formats. However, you need more code for customization, especially when positioning images precisely or implementing transparency and rotation. The library requires manual handling of coordinate systems and scaling calculations. You often need to implement your own viewport controls for responsive sizing.
How Do They Handle Large Files and Complex Operations?
IronPDF: IronPDF handles large PDFs and images efficiently through improve memory management. Performance excels when generating or modifying PDFs with embedded graphics, suitable for server applications and Azure deployments. The library supports async operations and multithreading for batch processing. Performance optimization features include intelligent caching and parallel PDF generation.
iTextSharp: iTextSharp can be slower with large files or complex image operations. Memory usage becomes a concern when processing multiple images simultaneously or working with high-resolution images. However, it remains suitable for most applications when properly configured. The library lacks built-in compression optimization for batch operations.
What Are the Cost Implications for Commercial Use?
IronPDF: IronPDF offers a perpetual license with transparent pricing through one-time purchase. This avoids recurring subscription costs. The library includes free trial options and complete technical support. License key management is straightforward with multiple configuration options.
iTextSharp: iTextSharp uses AGPL for open-source use, requiring source code release. Commercial licenses avoid this requirement. The licensing complexity can challenge commercial applications. Understanding license upgrades and extensions requires careful planning.
How Do I Add Images to PDFs Using IronPDF?
How Do I Install and Configure IronPDF?
Install IronPDF in your C# or Visual Basic project via NuGet. The library supports multiple installation methods including Windows Installer and Docker deployment:
Install-Package IronPdf
Once installed, you can start adding images using IronPDF's API reference. The library works seamlessly across Windows, Linux, and macOS platforms.
What Does Basic Image Addition Look Like in IronPDF?
Quickstart: Add Image to PDF with IronPDF
Adding images to PDFs with IronPDF requires minimal code using the stamping API.
Get started making PDFs with NuGet now:
Install IronPDF with NuGet Package Manager
Copy and run this code snippet.
using IronPdf; using IronPdf.Editing; class Program { public static void Main(string[] args) { // Create a renderer to convert HTML to PDF ChromePdfRenderer renderer = new ChromePdfRenderer(); // Render a basic PDF with some HTML content PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>"); // Create an ImageStamper with the image URL ImageStamper stamper = new ImageStamper(new Uri("___PROTECTED_URL_61___")); // Configure image position and size stamper.HorizontalAlignment = HorizontalAlignment.Center; stamper.VerticalAlignment = VerticalAlignment.Middle; stamper.Width = 200; // Width in pixels stamper.Height = 100; // Height in pixels // Apply the stamp (image) to the PDF document pdf.ApplyStamp(stamper); // Save the modified PDF to a file pdf.SaveAs("output.pdf"); } }Deploy to test on your live environment
How Can I Add Watermarks and Background Images?
IronPDF excels at adding watermarks and background images to existing PDFs. The library supports multiple stamping operations and custom positioning:
using IronPdf;
using IronPdf.Editing;
// Load an existing PDF
PdfDocument pdf = PdfDocument.FromFile("invoice.pdf");
// Create a watermark with transparency
ImageStamper watermark = new ImageStamper("watermark.png")
{
Opacity = 30, // 30% opacity for subtle watermarking
Rotation = -45, // Diagonal watermark
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Middle
};
// Apply watermark to all pages
pdf.ApplyStamp(watermark);
// Add a header logo
ImageStamper logo = new ImageStamper("company-logo.png")
{
HorizontalOffset = Length.Millimeters(10),
VerticalOffset = Length.Millimeters(10),
Width = 150,
Height = 50
};
pdf.ApplyStamp(logo, PageSelection.FirstPage);
pdf.SaveAs("watermarked-invoice.pdf");using IronPdf;
using IronPdf.Editing;
// Load an existing PDF
PdfDocument pdf = PdfDocument.FromFile("invoice.pdf");
// Create a watermark with transparency
ImageStamper watermark = new ImageStamper("watermark.png")
{
Opacity = 30, // 30% opacity for subtle watermarking
Rotation = -45, // Diagonal watermark
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Middle
};
// Apply watermark to all pages
pdf.ApplyStamp(watermark);
// Add a header logo
ImageStamper logo = new ImageStamper("company-logo.png")
{
HorizontalOffset = Length.Millimeters(10),
VerticalOffset = Length.Millimeters(10),
Width = 150,
Height = 50
};
pdf.ApplyStamp(logo, PageSelection.FirstPage);
pdf.SaveAs("watermarked-invoice.pdf");You can also create complex layouts with multiple images:
// Add images from Base64 strings
string base64Image = Convert.ToBase64String(File.ReadAllBytes("signature.png"));
HtmlStamper signatureStamp = new HtmlStamper($"<img src='data:image/png;base64,{base64Image}'/>");
signatureStamp.HorizontalAlignment = HorizontalAlignment.Right;
signatureStamp.VerticalAlignment = VerticalAlignment.Bottom;
pdf.ApplyStamp(signatureStamp);// Add images from Base64 strings
string base64Image = Convert.ToBase64String(File.ReadAllBytes("signature.png"));
HtmlStamper signatureStamp = new HtmlStamper($"<img src='data:image/png;base64,{base64Image}'/>");
signatureStamp.HorizontalAlignment = HorizontalAlignment.Right;
signatureStamp.VerticalAlignment = VerticalAlignment.Bottom;
pdf.ApplyStamp(signatureStamp);
This example uses the ChromePdfRenderer class to render a new PDF from an HTML string. Using IronPDF's image stamping tool, you create an image from the provided URL and apply it to the PDF. This demonstrates adding images to your PDF page with minimal code. The rendering options provide full control over output quality.
How Can I Control Image Position and Dimensions in IronPDF?
IronPDF provides extensive customization for image placement. You specify page location by setting alignment and offset through the stamping tool's positioning feature. The library supports both absolute positioning with coordinates and relative positioning using alignment options. Advanced features include custom paper sizes and margin control for precise layouts.
How Do I Add Images to PDFs Using iTextSharp?
How Do I Install and Configure iTextSharp?
Install iTextSharp via NuGet. Unlike IronPDF's complete platform support, iTextSharp has limited deployment options:
Install-Package itext7
Once configured, proceed to add images using iTextSharp's document manipulation features. The library requires additional configuration for font management and UTF-8 support.
What Does Basic Image Addition Look Like in iTextSharp?
Here's how to insert an image using iTextSharp:
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.IO.Image;
class Program
{
public static void Main(string[] args)
{
// Initialize PDF writer
var pdfWriter = new PdfWriter("output.pdf");
// Initialize PDF document
var pdfDocument = new iText.Kernel.Pdf.PdfDocument(pdfWriter);
// Initialize document
var document = new Document(pdfDocument);
// Create ImageData from image file
ImageData imageData = ImageDataFactory.Create("iText.png");
// Create an Image instance
Image image = new Image(imageData);
// Set fixed position for the image in the PDF
image.SetFixedPosition(50, 100); // x, y coordinates
// Scale image to fit within specified dimensions
image.ScaleToFit(200, 200); // Width, Height
// Add image to document
document.Add(image);
// Close the document
document.Close();
}
}using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.IO.Image;
class Program
{
public static void Main(string[] args)
{
// Initialize PDF writer
var pdfWriter = new PdfWriter("output.pdf");
// Initialize PDF document
var pdfDocument = new iText.Kernel.Pdf.PdfDocument(pdfWriter);
// Initialize document
var document = new Document(pdfDocument);
// Create ImageData from image file
ImageData imageData = ImageDataFactory.Create("iText.png");
// Create an Image instance
Image image = new Image(imageData);
// Set fixed position for the image in the PDF
image.SetFixedPosition(50, 100); // x, y coordinates
// Scale image to fit within specified dimensions
image.ScaleToFit(200, 200); // Width, Height
// Add image to document
document.Add(image);
// Close the document
document.Close();
}
}How Can I Add Multiple Images and Handle Complex Layouts?
For complex scenarios like creating product catalogs or photo albums, you manage layout manually. IronPDF's table of contents feature and bookmark support can organize multi-page documents:
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.IO.Image;
using iText.Layout.Properties;
// Create a grid of images
var pdfWriter = new PdfWriter("catalog.pdf");
var pdfDocument = new PdfDocument(pdfWriter);
var document = new Document(pdfDocument);
// Add images in a grid layout
float xPosition = 50;
float yPosition = 750;
int imagesPerRow = 3;
int currentImage = 0;
string[] imageFiles = { "product1.jpg", "product2.jpg", "product3.jpg",
"product4.jpg", "product5.jpg", "product6.jpg" };
foreach (string imagePath in imageFiles)
{
ImageData imageData = ImageDataFactory.Create(imagePath);
Image image = new Image(imageData);
// Calculate position
int column = currentImage % imagesPerRow;
int row = currentImage / imagesPerRow;
float x = xPosition + (column * 180);
float y = yPosition - (row * 250);
image.SetFixedPosition(x, y);
image.ScaleToFit(150, 200);
document.Add(image);
currentImage++;
}
document.Close();using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.IO.Image;
using iText.Layout.Properties;
// Create a grid of images
var pdfWriter = new PdfWriter("catalog.pdf");
var pdfDocument = new PdfDocument(pdfWriter);
var document = new Document(pdfDocument);
// Add images in a grid layout
float xPosition = 50;
float yPosition = 750;
int imagesPerRow = 3;
int currentImage = 0;
string[] imageFiles = { "product1.jpg", "product2.jpg", "product3.jpg",
"product4.jpg", "product5.jpg", "product6.jpg" };
foreach (string imagePath in imageFiles)
{
ImageData imageData = ImageDataFactory.Create(imagePath);
Image image = new Image(imageData);
// Calculate position
int column = currentImage % imagesPerRow;
int row = currentImage / imagesPerRow;
float x = xPosition + (column * 180);
float y = yPosition - (row * 250);
image.SetFixedPosition(x, y);
image.ScaleToFit(150, 200);
document.Add(image);
currentImage++;
}
document.Close();
The image is added at coordinates (50, 100) and scaled to fit within 200x200 pixels. The PdfWriter creates the output file, enabling PDF writer functionality for handling images. For better organization, consider using page numbers and headers/footers.
How Can I Control Image Position and Dimensions in iTextSharp?
iTextSharp provides control over positioning and size through manual coordinate calculations. You scale images while maintaining aspect ratio or stretch to specific dimensions. The SetFixedPosition method offers precise placement control, and you can manipulate alignment and rotation. However, it lacks IronPDF's viewport controls and responsive sizing options.
How Do IronPDF and iTextSharp Compare in Performance?
Both libraries handle image addition to PDFs with notable differences:
IronPDF improve for performance, handling large documents with multiple images efficiently. It renders PDFs faster, especially for graphically intensive documents. The library supports async operations and parallel processing for improved throughput. Memory stream operations reduce disk I/O for better performance.
- iTextSharp offers good performance but may struggle with very large PDFs or numerous high-resolution images. While efficient, some developers report slower rendering times compared to IronPDF in complex use cases involving multiple page operations. The library lacks built-in linearization support for web optimization.
What Are the Advanced Image Features Available?
How Do They Handle Different Image Formats?
IronPDF supports complete image formats:
- JPEG/JPG with quality optimization
- PNG with transparency support
- GIF (static and animated frames)
- SVG with vector graphics
- TIFF including multi-page TIFF files
- WebP for modern web images
- Base64 encoded images
- Images from Azure Blob Storage
iTextSharp supports standard formats:
- JPEG/JPG
- PNG with alpha channel
- GIF (first frame only)
- TIFF (single page)
- BMP and other bitmap formats
What About Image Quality and Compression?
IronPDF provides built-in compression options balancing file size and quality. The library offers sanitization features and flattening capabilities:
// Configure compression when rendering
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.JpegQuality = 85; // 0-100 quality scale
// Compress existing PDFs with images
PdfDocument pdf = PdfDocument.FromFile("large-images.pdf");
pdf.CompressImages(60); // Compress to 60% quality
pdf.SaveAs("compressed.pdf");
// Additional optimization options
renderer.RenderingOptions.GrayScale = true; // Convert to grayscale
renderer.RenderingOptions.DPI = 150; // Reduce DPI for web viewing// Configure compression when rendering
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.JpegQuality = 85; // 0-100 quality scale
// Compress existing PDFs with images
PdfDocument pdf = PdfDocument.FromFile("large-images.pdf");
pdf.CompressImages(60); // Compress to 60% quality
pdf.SaveAs("compressed.pdf");
// Additional optimization options
renderer.RenderingOptions.GrayScale = true; // Convert to grayscale
renderer.RenderingOptions.DPI = 150; // Reduce DPI for web viewingiTextSharp requires manual compression handling through image data manipulation, increasing implementation complexity for quality controls. You must implement your own grayscale conversion and DPI adjustments.
How Can I Extract Images from Existing PDFs?
IronPDF provides reliable image extraction capabilities:
// Extract all images from a PDF
PdfDocument pdf = PdfDocument.FromFile("document.pdf");
var images = pdf.ExtractAllImages();
foreach (var image in images)
{
// Save extracted images
image.SaveAs($"extracted_image_{images.IndexOf(image)}.png");
}
// Extract images from specific pages
var pageImages = pdf.ExtractImagesFromPage(0); // First page// Extract all images from a PDF
PdfDocument pdf = PdfDocument.FromFile("document.pdf");
var images = pdf.ExtractAllImages();
foreach (var image in images)
{
// Save extracted images
image.SaveAs($"extracted_image_{images.IndexOf(image)}.png");
}
// Extract images from specific pages
var pageImages = pdf.ExtractImagesFromPage(0); // First pageWhat Are the Licensing and Pricing Models?
IronPDF: IronPDF offers a straightforward perpetual license requiring one-time purchase. This approach provides clear benefits avoiding ongoing costs or open-source licensing requirements. The library includes complete support and regular updates. License verification is automated and supports multiple deployment scenarios.
- iTextSharp: iTextSharp follows AGPL licensing, free for open-source projects but requiring public source code release for web applications. Commercial licenses avoid AGPL restrictions. The licensing model can complicate cloud deployments.
Which Library Should I Choose for Adding Images to PDFs?

Both IronPDF and iTextSharp provide effective tools for adding images to PDFs in C#, each with distinct advantages. IronPDF excels with ease of use, performance, and licensing flexibility, making it ideal for handling complex PDFs and images with minimal code. It offers better scalability for large PDFs and provides one-time purchase licensing, avoiding recurring costs or complicated open-source restrictions.
The library's support for modern formats like SVG and WebP, combined with built-in compression capabilities and intuitive positioning APIs, suits enterprise applications requiring high-quality document generation. IronPDF's Chrome rendering engine ensures pixel-perfect output across all platforms.
iTextSharp suits open-source projects, though requiring more code for equivalent results and potentially facing performance issues with larger PDFs. Its lower-level API provides granular control but increases development complexity. The library lacks modern features like responsive CSS support and JavaScript rendering.
For enterprise applications, IronPDF's advantages include Docker support, AWS Lambda compatibility, and Azure Functions integration. The library also provides PDF/A compliance and PDF/UA accessibility for regulatory requirements.
Ready to simplify your PDF image handling? IronPDF delivers efficient image addition to PDFs with minimal code. Try IronPDF and experience simplified image integration in your C# projects. The implementation handles the complexity for you, saving time and improve your PDF generation workflow. Explore the complete feature set and join thousands of developers who've simplified their PDF operations.
Frequently Asked Questions
How can I add images to PDFs in a .NET application?
You can use IronPDF to add images to PDFs by utilizing its ImageStamper feature, which allows easy image embedding with precise control over placement and scaling.
What are the performance benefits of using IronPDF for large PDF files?
IronPDF is optimized for high performance, particularly with large PDF files and high-resolution images, making it ideal for server-based applications that require efficient processing.
How does IronPDF simplify the process of embedding images into PDFs?
IronPDF simplifies image embedding by providing an intuitive API that requires minimal code to place and scale images within a PDF document, enhancing developer productivity.
What is the licensing model for IronPDF compared to iTextSharp?
IronPDF offers a perpetual license with a one-time purchase, eliminating recurring subscription costs, while iTextSharp uses an AGPL license for open-source use with a commercial option for proprietary projects.
Can you provide a code example for adding an image to a PDF using IronPDF?
Certainly! You can use IronPDF's PdfDocument and ImageStamper classes to embed images into PDFs with just a few lines of code, as demonstrated in the example within the article.
How does image placement customization differ between IronPDF and iTextSharp?
IronPDF offers straightforward image placement customization with alignment and offset settings, while iTextSharp provides detailed control over image positioning using methods like SetFixedPosition.
What are the key considerations for choosing between IronPDF and iTextSharp?
Choosing between IronPDF and iTextSharp depends on factors like ease of use, performance with large files, and licensing needs. IronPDF is favored for its user-friendly approach and scalability, while iTextSharp suits open-source projects.
Why is IronPDF recommended for high-performance server applications?
IronPDF's architecture is designed for high performance, efficiently handling large documents and images, which makes it an excellent choice for server applications that demand speed and reliability.
What are common troubleshooting steps when adding images to PDFs?
When troubleshooting image embedding issues in PDFs, ensure that the image paths are correct, check for any file access permissions, and verify that the image format is supported by the PDF library being used.
How does the trial version of IronPDF help developers?
The trial version of IronPDF allows developers to explore its features and test its capabilities in handling PDF image embedding, providing an opportunity to simplify PDF processing in C# projects.








