---
title: "Add an inline icon inside a PDF paragraph in C#"
url: https://recursiveai.org/onepdf/cookbook/add-inline-icon-to-pdf-text/
description: "Place a drawn icon between words in a PDF paragraph with C#. The icon wraps with the text, without fixed page coordinates."
version: "1.25.1"
---

# Add an inline icon inside a PDF paragraph in C#

**OnePDF** is a free, open-source PDF library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OnePdf.Layout) · [GitHub](https://github.com/recursive-ai-oss/onepdf-csharp) · [Docs](https://recursiveai.org/onepdf/docs/) · [Download example (.zip)](https://recursiveai.org/onepdf/cookbook/add-inline-icon-to-pdf-text/add-inline-icon-to-pdf-text.zip)

Use `InlineCanvas()` to draw an icon that moves with the words when a paragraph wraps.

```shell
dotnet add package RecursiveAI.OnePdf.Layout
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OnePdf.Layout;

LayoutDocument.Compose(doc => doc.Page(p =>
{
    p.Size(216, 144);
    p.Margin(24);
    p.Content().Text(t =>
    {
        t.Span("Delivery status: ");
        t.InlineCanvas(9, 9, s =>
        {
            s.Builder.SetFillRgb(0, 0.5, 0);
            s.Builder.Ellipse(0, 0, 9, 9);
            s.Builder.Fill();
        }).Artifact().AlignMiddle();
        t.Span(" Shipped. Tracking is ready.");
    });
})).Save("inline.pdf");
Console.WriteLine("Wrote inline.pdf");
```

Unzip [the example](https://recursiveai.org/onepdf/cookbook/add-inline-icon-to-pdf-text/add-inline-icon-to-pdf-text.zip), then `dotnet run`.

```text
Wrote inline.pdf
```



Open `inline.pdf`: a small green dot sits between “Delivery status:” and “Shipped.” The rest of the sentence wraps onto the next line. The code draws the dot, so there’s no image file to supply. If you make the icon wider than the line, wrapping won’t squeeze it: the icon overflows on a line of its own.

## Variations

**Keep the icon with the surrounding words.** Change the end of the `InlineCanvas` call to:

```csharp
}).Artifact().AlignMiddle().KeepWithNeighbours();
```

**Give a meaningful icon a description.** If the dot itself conveys a status that the words don’t say, use this instead of `Artifact()`:

```csharp
}).AltText("Shipped").AlignMiddle();
```

Remove the duplicate “Shipped.” from the next span if you use the icon in place of that word.

**Use a PNG or JPEG icon file.** Replace the `InlineCanvas` call with this snippet. It uses `status.png`, a green check mark included in the download; you can substitute your own PNG or JPEG.

```csharp
byte[] icon = File.ReadAllBytes("status.png");
t.InlineImage(icon, 9, 9)
    .Artifact().AlignMiddle();
```

```text
Wrote inline.pdf
```

The check mark appears in place of the dot, between “Delivery status:” and “Shipped.”

## Related recipes

- [Create a PDF file in C#](https://recursiveai.org/onepdf/cookbook/create-pdf/)
- [Create an accessible PDF/UA document](https://recursiveai.org/onepdf/cookbook/create-pdf-ua/)

## The short answer

Call `InlineCanvas` between two `Span` calls in `Text(t => ...)` when you generate the paragraph. The two size arguments are in PDF points, and the canvas draws in its own small box. You set coordinates inside that box, not on the page. For an existing PNG or JPEG icon, use `InlineImage` in the same place. Neither call inserts an icon into a paragraph in an already saved PDF.

## How do I put an icon and text on the same line?

Put both in one paragraph. A separate image block may sit above or below the text, and an image drawn at an absolute position won’t move when a longer label makes the paragraph wrap. Here the dot is a single, indivisible item in the text. A line can break before or after it unless you call `KeepWithNeighbours()`. That’s useful if the icon acts as a marker for the next word. Check the result in your narrowest column: keeping more content together leaves the layout fewer places to break the line.

Use `AlignMiddle()` to center the drawing against the text, not against the whole paragraph. With the default baseline alignment, the bottom edge of the canvas sits on the text baseline. A tall icon can make its line taller than neighboring lines, even if the surrounding font size is unchanged. Start with an icon close to the height of the letters, then adjust its size for the font you use.

## How do I add alt text to an icon in a PDF?

Use `AltText` when the picture adds information. In a tagged document, OnePDF records the icon as a figure inside the paragraph and uses the description in text extraction. When the text already says “Shipped,” the green dot only repeats the status. Marking it with `Artifact()` keeps it out of the tag tree and text extraction; the dot still draws. Marking up an individual icon doesn’t by itself make the whole document accessible.
