๐Ÿ–ผ๏ธ Images in PDFs

JPEG and PNG images with alt text, bounding boxes, and aspect-preserving scaling.

C# โ€” Accessible Images
// Load image from file
var image = PdfImage.FromFile("photo.jpg");

// Create figure structure with alt text
var figure = root.AddChild(StructureType.Figure,
    "Company logo on blue background");

// REQUIRED for PDF/UA: bounding box
figure.BBox = new[] {
    72.0, 500.0, 300.0, 680.0
};

// Tag the image content
page.BeginTaggedContent(figure);
page.AddImage(image, 72, 500, 228, 180);
page.EndTaggedContent();

// Scale to fit preserving aspect ratio
var photo = PdfImage.FromFile("landscape.jpg");
var photoFig = root.AddChild(StructureType.Figure,
    "Sunset over the ocean");
photoFig.BBox = new[] {
    72.0, 250.0, 472.0, 450.0
};
page.BeginTaggedContent(photoFig);
page.AddImageScaled(photo,
    72, 250, maxWidth: 400, maxHeight: 200);
page.EndTaggedContent();
Screenshot of the Images PDF showing a placeholder rectangle where an image would appear, with the surrounding tagged structure visible including Figure elements with alt text descriptions

You should see a bold "Working with Images" heading, a short introduction paragraph, and a light blue-grey filled rectangle (228 ร— 180 pt) with a thin grey border representing an image placeholder. Below it, three lines of Courier code show the API calls needed to embed a real JPEG or PNG.
File: 09_images.pdf

โ™ฟ Accessibility Tip

Every image must have: (1) a Figure structure element with meaningful alt text, and (2) a BBox bounding box. Decorative images should be marked as artifacts with BeginArtifact(PdfArtifactType.Layout) instead.

Supported Formats

FormatMethodNotes
JPEGPdfImage.FromFile("photo.jpg")DCTDecode passthrough โ€” no re-encoding
PNGPdfImage.FromFile("logo.png")Deconstructed with row filters, alpha โ†’ SMask
StreamPdfImage.FromStream(stream)Any seekable stream
BytesPdfImage.FromBytes(data)In-memory byte array