---
title: "Images"
canonical_url: "https://www.compdf.com/guides/generation-sdk/dotnet-core/generation/layout-api-images"
md_url: "https://www.compdf.com/guides/generation-sdk/dotnet-core/generation/layout-api-images.md"
description: "ComPDF SDK Guides. In this developer's guide, all the details and how to use ComPDF for SDK Guides will be covered in depth."
---

# Images

## Adding Images

```csharp
// Create image from file path
CImage image = div.CreateImage("path/to/image.png");

// Set image dimensions (point unit)
image.SetWidth(300);
image.SetHeight(200);

// Or use percentage
image.SetWidth(CUnitValue.CreatePercentValue(50));
```

## Image Scaling

```csharp
// Proportional scaling
image.Scale(0.5f, 0.5f); // Scale to 50%

// Fit to specified dimensions (maintain aspect ratio)
image.ScaleToFit(400, 300);

// Scale to exact dimensions (may distort)
image.ScaleAbsolute(400, 300);

// Auto scaling
image.SetAutoScale(true);
image.SetAutoScaleWidth(true);
image.SetAutoScaleHeight(true);
```

## Image Positioning

```csharp
// Absolute positioning
image.SetAbsolutePosition(100, 100);

// Set margin
image.SetMargin(10);
image.SetMargins(10, 20, 10, 20); // Top, Right, Bottom, Left

// Set padding
image.SetPadding(5);
```
