agentleFS
aspose-pdfaspose-pdf/agentic-net-examples/AGENTS.md

agentic-net-examples

AGENTS.md2 starsChanged 4 months agoMITView on GitHub

AI-friendly C# code examples for Aspose.PDF for .NET

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

19 rules. About 0 are common, 10 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈10

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    When working in this repository:

    line 16
  2. Very specific:

    All examples must compile and run without errors using dotnet build and dotnet run

    line 18
  3. Distinctive:

    Follow the conventions, boundaries, and anti-patterns documented below exactly

    line 19
  4. Distinctive:

    Use the Command Reference section for build/run commands

    line 20
  5. Distinctive:

    Use this file and the nearest category agent guide for API rules and anti-patterns.

    line 176
  6. Very specific:

    Do not manually edit generated agent guide files or index.json unless the task explicitly asks for generator output changes.

    line 177
  7. Distinctive:

    Check with a human before doing any of these:

    line 240
  8. Very specific:

    Never use var for variable declarations

    line 249
  9. Very specific:

    Never use 0-based indexing for Pages, Annotations, or EmbeddedFiles

    line 250
  10. Very specific:

    Never use unqualified type names for Rectangle, Color, Path, Image, Matrix, Point

    line 251
  11. Very specific:

    Never use Aspose.Pdf.Saving namespace (it does not exist)

    line 252
  12. Very specific:

    Never mix Aspose.Pdf.LogicalStructure and Aspose.Pdf.Structure namespaces

    line 253
  13. Distinctive:

    Never modify agents.md files -- they are auto-generated

    line 254
  14. Very specific:

    Never modify the .csproj template -- it is generated

    line 255
  15. Distinctive:

    When a type name can resolve to multiple namespaces (especially with Aspose.Pdf, Aspose.Pdf.Drawing, System.IO, and System.Drawing), ALWAYS …

    line 299
  16. Distinctive:

    Always use fully qualified Aspose.Pdf.Rectangle and Aspose.Pdf.Color to avoid ambiguity with System.Drawing types.

    line 387
  17. Distinctive:

    All examples are standalone Console Applications

    line 512
  18. Distinctive:

    Every example must pass these verification steps.

    line 517
  19. Very specific:

    Ensure input.pdf exists in the same directory (where required)

    line 556

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Aspose.PDF for .NET Examples

AI-friendly repository containing validated C# examples for Aspose.PDF for .NET API.

Persona

You are a C# developer specializing in PDF processing using Aspose.PDF for .NET. When working in this repository:

  • Each .cs file is a standalone Console Application -- do not create multi-file projects
  • All examples must compile and run without errors using dotnet build and dotnet run
  • Follow the conventions, boundaries, and anti-patterns documented below exactly
  • Use the Command Reference section for build/run commands

Repository Overview

This repository contains 2636 working code examples demonstrating Aspose.PDF for .NET capabilities.

Statistics (as of 2026-07-21):

  • Total Examples: 2636
  • Categories: 35

Category Details

accessibility-and-tagged-pdfs

  • Examples: 45
  • Guide: AGENTS.md

basic-operations

  • Examples: 57
  • Guide: AGENTS.md

compare-pdf

  • Examples: 29
  • Guide: AGENTS.md

conversion

  • Examples: 102
  • Guide: AGENTS.md

document

  • Examples: 117
  • Guide: AGENTS.md

facades-acroforms

  • Examples: 41
  • Guide: AGENTS.md

facades-annotations

  • Examples: 106
  • Guide: AGENTS.md

facades-bookmarks

  • Examples: 35
  • Guide: AGENTS.md

facades-convert-documents

  • Examples: 36
  • Guide: AGENTS.md

facades-documents

  • Examples: 101
  • Guide: AGENTS.md

facades-edit-document

  • Examples: 213
  • Guide: AGENTS.md

facades-extract-images-and-text

  • Examples: 83
  • Guide: AGENTS.md

facades-fill-forms

  • Examples: 35
  • Guide: AGENTS.md

facades-forms

  • Examples: 85
  • Guide: AGENTS.md

facades-metadata

  • Examples: 40
  • Guide: AGENTS.md

facades-pages

  • Examples: 117
  • Guide: AGENTS.md

facades-secure-documents

  • Examples: 38
  • Guide: AGENTS.md

facades-sign-documents

  • Examples: 35
  • Guide: AGENTS.md

facades-stamps

  • Examples: 48
  • Guide: AGENTS.md

facades-texts-and-images

  • Examples: 28
  • Guide: AGENTS.md

facades-xmp-metadata

  • Examples: 44
  • Guide: AGENTS.md

graphs-zugferd-operators

  • Examples: 82
  • Guide: AGENTS.md

pages

  • Examples: 100
  • Guide: AGENTS.md

parse-pdf

  • Examples: 63
  • Guide: AGENTS.md

securing-and-signing-pdf

  • Examples: 78
  • Guide: AGENTS.md

stamping

  • Examples: 50
  • Guide: AGENTS.md

uncategorized

  • Examples: 1
  • Guide: AGENTS.md

working-with-annotations

  • Examples: 156
  • Guide: AGENTS.md

working-with-attachments

  • Examples: 50
  • Guide: AGENTS.md

working-with-forms

  • Examples: 230
  • Guide: AGENTS.md

working-with-graphs

  • Examples: 77
  • Guide: AGENTS.md

working-with-images

  • Examples: 72
  • Guide: AGENTS.md

working-with-tables

  • Examples: 96
  • Guide: AGENTS.md

working-with-text

  • Examples: 73
  • Guide: AGENTS.md

working-with-xml

  • Examples: 73
  • Guide: AGENTS.md

Contribution Workflow

This file is generated and is the canonical coding-agent guide for example code.

  • Use this file and the nearest category agent guide for API rules and anti-patterns.
  • Do not manually edit generated agent guide files or index.json unless the task explicitly asks for generator output changes.
  • For contribution workflow, validation expectations, and pull-request requirements, see CONTRIBUTING.md and .github/pull_request_template.md.

Boundaries

[OK] Always

These rules are mandatory for every example.

Use explicit types -- never use var

// CORRECT
Document document = new Document("input.pdf");
Page page = document.Pages[1];
TextFragmentAbsorber absorber = new TextFragmentAbsorber("search");

// WRONG
// var document = new Document("input.pdf");
// var page = document.Pages[1];

Use 1-based indexing for Pages, Annotations, EmbeddedFiles

// CORRECT -- first page is index 1
Page firstPage = document.Pages[1];
Annotation firstAnnotation = page.Annotations[1];
FileSpecification firstFile = document.EmbeddedFiles[1];

// WRONG -- index 0 throws IndexOutOfRangeException
// Page page = document.Pages[0];

Fully qualify ambiguous types (Rectangle, Color, Path, Image, Point, Matrix)

// CORRECT
Aspose.Pdf.Rectangle rect = new Aspose.Pdf.Rectangle(100, 200, 300, 400);
Aspose.Pdf.Drawing.Rectangle drawRect = new Aspose.Pdf.Drawing.Rectangle(50, 50, 200, 100);
Aspose.Pdf.Color pdfColor = Aspose.Pdf.Color.Blue;

// WRONG -- ambiguous CS0104
// Rectangle rect = new Rectangle(100, 200, 300, 400);
// Color color = Color.Blue;

Use using blocks for IDisposable objects

// CORRECT
using (Document document = new Document("input.pdf"))
{
    // work with document
    document.Save("output.pdf");
}

Save the document after all modifications

Document document = new Document("input.pdf");
// ... make modifications ...
document.Save("output.pdf");

[WARN]️ Ask First

Check with a human before doing any of these:

  • Creating multi-file projects -- each example must be a single .cs file
  • Using deprecated APIs -- check the Aspose.PDF changelog for the current API surface
  • Adding NuGet packages beyond Aspose.PDF -- the .csproj template only includes Aspose.PDF
  • Modifying shared infrastructure -- .csproj templates, agents.md files, CI configs

🚫 Never

See the full Common Mistakes section below for code-level prohibitions with examples.

  • Never use var for variable declarations
  • Never use 0-based indexing for Pages, Annotations, or EmbeddedFiles
  • Never use unqualified type names for Rectangle, Color, Path, Image, Matrix, Point
  • Never use Aspose.Pdf.Saving namespace (it does not exist)
  • Never mix Aspose.Pdf.LogicalStructure and Aspose.Pdf.Structure namespaces
  • Never modify agents.md files -- they are auto-generated
  • Never modify the .csproj template -- it is generated

Common Mistakes (Anti-Patterns)

These are verified mistakes that cause build failures. Never use the wrong patterns.

Borderinfo No Color Width Properties

BorderInfo does not have settable .Color or .Width properties. Use the constructor instead: new BorderInfo(BorderSide.All, (float)width, color). Pass BorderSide, width as float, and Aspose.Pdf.Color t

// WRONG
BorderInfo b = new BorderInfo();
b.Color = Aspose.Pdf.Color.Blue;  // CS1061
b.Width = 1.5;                    // CS1061
// CORRECT
Aspose.Pdf.Color borderColor = Aspose.Pdf.Color.Blue;
float borderWidth = 1.5f;
cell.Border = new BorderInfo(BorderSide.All, borderWidth, borderColor);
// Width-only variant:
cell.Border = new BorderInfo(BorderSide.All, 1f);
// Cast from double if needed:
cell.Border = new BorderInfo(BorderSide.All, (float)someDoubleWidth, Aspose.Pdf.Color.Green);

Rotation Enum Uses On Prefix

The Aspose.Pdf.Rotation enum values use the 'on' prefix, NOT 'Rotate'. The correct values are: Rotation.None, Rotation.on90, Rotation.on180, Rotation.on270, Rotation.on360. Using 'Rotate90', 'Rotate18

// WRONG
page.Rotate = Rotation.Rotate180; // CS0117
page.Rotate = Rotation.Rotate90;  // CS0117
// CORRECT
page.Rotate = Rotation.on180;
page.Rotate = Rotation.on90;
page.Rotate = Rotation.on270;

Prefer Fully Qualified Names For Ambiguous Types

When a type name can resolve to multiple namespaces (especially with Aspose.Pdf, Aspose.Pdf.Drawing, System.IO, and System.Drawing), ALWAYS use fully qualified names for ANY type that exists in more t

// WRONG
Rectangle rect = new Rectangle(100, 500, 300, 550); // CS0104
Path.GetFileName("input.pdf");                      // CS0104
Image img = Image.FromFile("photo.jpg");             // CS0104
Color c = Color.Blue;                                // CS0104
// CORRECT
Aspose.Pdf.Rectangle pageRect = new Aspose.Pdf.Rectangle(100, 500, 300, 550);
Aspose.Pdf.Drawing.Rectangle shapeRect = new Aspose.Pdf.Drawing.Rectangle(100, 500, 200, 100);
System.IO.Path.GetFileName("input.pdf");
Aspose.Pdf.Image pdfImg = new Aspose.Pdf.Image();
System.Drawing.Image sysImg = System.Drawing.Image.FromFile("photo.jpg");
Aspose.Pdf.Color pdfColor = Aspose.Pdf.Color.Blue;
System.Drawing.Color sysColor = System.Drawing.Color.Blue;
Aspose.Pdf.Point pdfPoint = new Aspose.Pdf.Point(100, 200);
// ...

Annotation Collection One Based Indexing

Aspose.Pdf annotation collections use 1-based indexing, same as Pages. page.Annotations[1] is the first annotation. page.Annotations[0] throws an exception. page.Annotations.Delete(index) also expects

// WRONG
page.Annotations[0]; // throws IndexOutOfRangeException
page.Annotations.Delete(page.Annotations.Count - 1); // deletes second-to-last
// CORRECT
for (int i = 1; i <= page.Annotations.Count; i++)
{
    Annotation ann = page.Annotations[i];
}
page.Annotations.Delete(page.Annotations.Count);

Annotation Title Requires Markup Annotation

The 'Title' property belongs to MarkupAnnotation, NOT the base Annotation class. When iterating page.Annotations or using FindByName(), the returned type is Annotation which does not have Title. You m

// WRONG
Annotation ann = page.Annotations[1];
Console.WriteLine(ann.Title); // CS1061
// CORRECT
Annotation ann = page.Annotations[1];
string title = ann is MarkupAnnotation markup ? markup.Title : "N/A";
Console.WriteLine($"Title={title}, Contents={ann.Contents}");
Annotation retrieved = page.Annotations.FindByName("MyNote");
if (retrieved is MarkupAnnotation ma)
{
    Console.WriteLine(ma.Title);
}

Border Requires Parent Annotation

The Border class has no parameterless constructor — it requires an Annotation parent argument: new Border(annotation). Border also has NO Color property; border color is controlled by the annotation's

// WRONG
var ann = new TextAnnotation(page, rect)
{
    Border = new Border { Width = 1, Color = Aspose.Pdf.Color.Black }
};
Errors: CS1729, CS1061
var ann = new TextAnnotation(page, rect)
...
// CORRECT
TextAnnotation ann = new TextAnnotation(page, rect)
{
    Title = "Note",
    Contents = "Hello",
    Color = Aspose.Pdf.Color.Yellow
};
ann.Border = new Border(ann) { Width = 1 };

Qualify Rectangle And Color

Always use fully qualified Aspose.Pdf.Rectangle and Aspose.Pdf.Color to avoid ambiguity with System.Drawing types. Even if System.Drawing is not explicitly referenced, implicit usings or transitive de

// WRONG
Rectangle rect = new Rectangle(100, 500, 300, 550);
txtAnn.Color = Color.Yellow;
// CORRECT
Aspose.Pdf.Rectangle rect = new Aspose.Pdf.Rectangle(100, 500, 300, 550);
txtAnn.Color = Aspose.Pdf.Color.Yellow;

Mhtsaveoptions Namespace Missing

The MhtSaveOptions class is not in the Aspose.Pdf namespace — it resides in Aspose.Pdf.Facades. You must add 'using Aspose.Pdf.Facades;' and ensure the Aspose.PDF.dll reference includes the Facades as

// WRONG
using Aspose.Pdf; // alone is insufficient
MhtSaveOptions mhtOptions = new MhtSaveOptions(); // ❌ CS0246
// CORRECT
using Aspose.Pdf;
using Aspose.Pdf.Annotations;
using Aspose.Pdf.Facades; // ← Required for MhtSaveOptions
MhtSaveOptions mhtOptions = new MhtSaveOptions
{
    PartsEmbeddingMode = MhtSaveOptions.PartsEmbeddingModes.EmbedAllIntoMht
};

Caret Annotation Symbol Missing

The enum 'CaretAnnotationSymbol' does not exist in Aspose.Pdf.Annotations. The 'Symbol' property of 'CaretAnnotation' expects a value of type 'Aspose.Pdf.Annotations.CaretSymbol', which is an enum def

// WRONG
Symbol = CaretAnnotationSymbol.Insert // ❌ enum does not exist
// CORRECT
using Aspose.Pdf.Annotations;
...
CaretAnnotation caret = new CaretAnnotation(page, rect)
{
    Symbol = CaretSymbol.Insert,
    Contents = "...",
    Color = Aspose.Pdf.Color.Red
};

Fix Texfragment Margin And Color Ambiguity

The TeXFragment class does not have a 'Margin' property; instead, use 'TopMargin', 'BottomMargin', etc. Also, 'Color' is ambiguous between System.Drawing.Color and Aspose.Pdf.Color — use fully qualifi

// WRONG
TeXFragment texFragment = new TeXFragment(...);
texFragment.Margin = new Margin { Top = 20, Bottom = 20 }; // ❌ No such property
DefaultAppearance appearance = new DefaultAppearance(..., Color.Black); // ❌ ambiguous
// CORRECT
TeXFragment texFragment = new TeXFragment(@"\frac{a}{b} = c", true);
texFragment.HorizontalAlignment = HorizontalAlignment.Center;
texFragment.TopMargin = 20;
texFragment.BottomMargin = 20;
DefaultAppearance appearance = new DefaultAppearance("Helvetica", 12, Aspose.Pdf.Color.Black);

Domain Knowledge

Cross-cutting rules and API-specific gotchas.

  • Create a new {doc} and add a {page} via {doc}.Pages.Add(). (Applies to: Graphs, Working-Document)
  • Set {table}.ColumnWidths to a space‑separated string of column widths (e.g., "40 100 100") and assign {table}.DefaultCellBorder = new BorderInfo(BorderSide.All, {float}) to apply a uniform border to all cells. (Applies to: Tables)
  • Populate the table from a System.Data.DataTable using {table}.ImportDataTable({data_table}, true, 0, 0, {int}, {int}) where the last two integers represent the total number of rows (including header) and the number of columns. (Applies to: Tables)
  • Iterate over {row}.Cells to customize appearance: set {cell}.BackgroundColor, {cell}.DefaultCellTextState.Font, {cell}.DefaultCellTextState.ForegroundColor, and {cell}.DefaultCellTextState.HorizontalAlignment. (Applies to: Tables)
  • Apply distinct styling to the header row (row index 0) versus data rows (row index >= 1) by using separate loops or conditional logic. (Applies to: Tables)
  • Create a TextFragmentAbsorber with a {string_literal} search phrase and apply it to a specific {page} of a {doc} via page.Accept(absorber). (Applies to: Text)
  • Iterate over absorber.TextFragments; for each {text_fragment}, set Text = {string_literal} and adjust TextState properties: Font = FontRepository.FindFont({font}), FontSize = {float}, ForegroundColor = Color.FromRgb({color}), BackgroundColor = Color.FromRgb({color}). (Applies to: Text)

Command Reference

Build and Run

# Create a new project (if needed)
dotnet new console -n ExampleProject --framework net10.0

# Add Aspose.PDF NuGet package
dotnet add package Aspose.PDF --version 26.7.0

# Build
dotnet build --configuration Release --verbosity minimal

# Run
dotnet run

Project File (.csproj)

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Aspose.PDF" Version="26.7.0" />
  </ItemGroup>
</Project>

Environment

  • .NET SDK: 10.0 or higher
  • NuGet: Aspose.PDF 26.7.0
  • All examples are standalone Console Applications
  • Each .cs file can be compiled and run independently

Testing Guide

Every example must pass these verification steps.

Build Verification

dotnet build --configuration Release --verbosity minimal
  • Success: Exit code 0, no CS error codes in output
  • Failure: Any error CS#### line indicates a build failure

Run Verification

dotnet run
  • Success: Exit code 0, no unhandled exception stack traces
  • Failure: Unhandled exception, System.Exception, or non-zero exit code

Expected Output Patterns

  • Console output confirming the operation (e.g., "PDF saved successfully")
  • Output files created in the working directory (e.g., output.pdf)
  • No NullReferenceException, IndexOutOfRangeException, or FileNotFoundException

Common Error Codes

CodeMeaningFix
CS0104Ambiguous type referenceUse fully qualified name (Aspose.Pdf.Rectangle)
CS1061Member does not exist on typeCheck API docs for correct property/method
CS0246Type or namespace not foundAdd missing using directive
CS0029Cannot convert typeCast explicitly or use correct type

How to Use These Examples

Prerequisites

  • .NET SDK (10.0 or higher)
  • Aspose.PDF for .NET (26.7.0 or higher)
  • NuGet package restore enabled

Running an Example

  1. Navigate to any category folder
  2. Each .cs file is a standalone Console Application
  3. Ensure input.pdf exists in the same directory (where required)
  4. Compile and run:
    dotnet run <example-file.cs>
<!-- AUTOGENERATED:START -->

Updated: 2026-07-21 | Run: 20260721_051355_c74604 | Examples: 2636 | Categories: 35

<!-- AUTOGENERATED:END -->

Maintained by an agentic example generation workflow | For AI-friendly guidance, see AGENTS.md | Last updated: 2026-07-21

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.