---
title: "Add text at coordinates in an existing PDF in C#"
url: https://recursiveai.org/onepdf/cookbook/add-text-at-coordinates-in-existing-pdf/
description: "Add visible text at a chosen baseline on an existing PDF page in C#, then reopen the file and extract both lines with OnePDF."
version: "1.25.1"
---

# Add text at coordinates in an existing PDF 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) · [GitHub](https://github.com/recursive-ai-oss/onepdf-csharp) · [Docs](https://recursiveai.org/onepdf/docs/) · [Download example (.zip)](https://recursiveai.org/onepdf/cookbook/add-text-at-coordinates-in-existing-pdf/add-text-at-coordinates-in-existing-pdf.zip)

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

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

```csharp
using OnePdf;
using var doc = PdfDocument.Open("input.pdf",
    new PdfOpenOptions { AllowEditing = true });
using var ink = doc.Pages[0].BeginContent();
var font = doc.AddStandardFont("Helvetica");
ink.SetFont(font, 12);
ink.DrawText("Reviewed", 72, 676);
ink.Commit();
doc.Save("reviewed.pdf");
Console.WriteLine("Saved reviewed.pdf");
```

On this page, `x` and `y` are in points (1/72 in) from the bottom-left corner, with `y` growing upward.

Writes `reviewed.pdf` with “Reviewed” on page 1.

```text
Saved reviewed.pdf
```

Unzip [the example](https://recursiveai.org/onepdf/cookbook/add-text-at-coordinates-in-existing-pdf/add-text-at-coordinates-in-existing-pdf.zip), then `dotnet run`.

Use `input.pdf` from the ZIP. It has three unrotated pages. Each says `Review this figure` in 12-point Helvetica at `(72, 700)`. The new line starts 24 points below it, at `(72, 676)`.

## The full program

The program commits the new text to the first page, saves a copy, then reopens it and extracts the page text.

```csharp
using OnePdf;
using var doc = PdfDocument.Open("input.pdf",
    new PdfOpenOptions { AllowEditing = true });
using var ink = doc.Pages[0].BeginContent();
var font = doc.AddStandardFont("Helvetica");
ink.SetFont(font, 12);
ink.DrawText("Reviewed", 72, 676);
ink.Commit();
doc.Save("reviewed.pdf");

using var saved = PdfDocument.Open("reviewed.pdf");
Console.WriteLine(saved.ExtractText()[0].Text.Trim());
```

`dotnet run` prints:

```text
Review this figure

Reviewed
```

If you dispose the builder without calling `Commit()`, the new text is discarded.

## Variations

To make the added text blue, set the fill color before calling `DrawText`:

```csharp
ink.SetFillRgb(0, 0, 0.65);
ink.DrawText("Reviewed", 72, 676);
```

## Related recipes

- [Extract text from a PDF](https://recursiveai.org/onepdf/cookbook/extract-text/)
- [Rotate or delete PDF pages](https://recursiveai.org/onepdf/cookbook/rotate-delete-pages/)

## The short answer

Open the PDF with `AllowEditing = true`. On the page you want to edit, call `BeginContent()`, select a font and call `DrawText(text, x, y)`. The coordinates identify the start of the baseline, not the upper-left corner of the letters. Commit the builder and save to a new file.

## How do I add text to an existing PDF without replacing the old text?

`BeginContent()` defaults to an overlay. It writes a separate stream after the existing content, so the original text remains in the file. If the two lines overlap, the new text paints on top; it doesn’t push the old text down or reflow the page. This is page content, not a text field a reader can fill in. In the example, extraction from the saved file returns the original line and the new one. If you want to place content behind the original page instead, pass `PdfContentPlacement.Underlay` to `BeginContent()`; an opaque background on that page can hide the new line.

## How do PDF coordinates work when placing text?

On the sample, x grows to the right, y grows upward, and the lower-left corner is `(0, 0)`. One unit is 1/72 inch. The second line uses the same x as the first but a smaller y so it lands below it. If a position comes from a top-left screen coordinate, don’t pass it straight to `DrawText`: the screen may use pixels and a downward y-axis. Check the PDF’s media box, visible crop, rotation and user unit before doing that conversion. The [content creation guide](https://recursiveai.org/onepdf/docs/content-creation/) explains that drawing uses the page’s default user space; the builder does not adjust the coordinates for the crop box or page rotation.

## How do I embed a font for the added text?

The sample uses standard Helvetica and doesn’t embed a font. `AddStandardFont` uses WinAnsi for Helvetica, so characters outside that encoding are written as `?` and reported in `doc.Diagnostics`. To embed a font, give `doc.AddFont` the bytes of a licensed font file that covers the characters you need, and pass its return value to `SetFont`. Embedding doesn’t add script shaping: `DrawText` itself doesn’t perform kerning, ligatures or bidirectional reordering.
