agentic-net-examples
AGENTS.md2 starsChanged 4 months agoMITView on GitHub
AI-friendly C# code examples for Aspose.PDF for .NET
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository36 other files it gives its agents.
- accessibility-and-tagged-pdfsAGENTS.md
- basic-operationsAGENTS.md
- compare-pdfAGENTS.md
- conversionAGENTS.md
- documentAGENTS.md
- facades-acroformsAGENTS.md
- facades-annotationsAGENTS.md
- facades-bookmarksAGENTS.md
- facades-convert-documentsAGENTS.md
- facades-documentsAGENTS.md
- facades-edit-documentAGENTS.md
- facades-extract-images-and-textAGENTS.md
- facades-fill-formsAGENTS.md
- facades-formsAGENTS.md
- facades-metadataAGENTS.md
- facades-pagesAGENTS.md
- facades-secure-documentsAGENTS.md
- facades-sign-documentsAGENTS.md
- facades-stampsAGENTS.md
- facades-texts-and-imagesAGENTS.md
- facades-xmp-metadataAGENTS.md
- graphs-zugferd-operatorsAGENTS.md
- pagesAGENTS.md
- parse-pdfAGENTS.md
- securing-and-signing-pdfAGENTS.md
- stampingAGENTS.md
- uncategorizedAGENTS.md
- working-with-annotationsAGENTS.md
- working-with-attachmentsAGENTS.md
- working-with-formsAGENTS.md
- working-with-graphsAGENTS.md
- working-with-imagesAGENTS.md
- working-with-tablesAGENTS.md
- working-with-textAGENTS.md
- working-with-xmlAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
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
- Distinctive: line 16
When working in this repository:
- Very specific: line 18
All examples must compile and run without errors using dotnet build and dotnet run
- Distinctive: line 19
Follow the conventions, boundaries, and anti-patterns documented below exactly
- Distinctive: line 20
Use the Command Reference section for build/run commands
- Distinctive: line 176
Use this file and the nearest category agent guide for API rules and anti-patterns.
- Very specific: line 177
Do not manually edit generated agent guide files or index.json unless the task explicitly asks for generator output changes.
- Distinctive: line 240
Check with a human before doing any of these:
- Very specific: line 249
Never use var for variable declarations
- Very specific: line 250
Never use 0-based indexing for Pages, Annotations, or EmbeddedFiles
- Very specific: line 251
Never use unqualified type names for Rectangle, Color, Path, Image, Matrix, Point
- Very specific: line 252
Never use Aspose.Pdf.Saving namespace (it does not exist)
- Very specific: line 253
Never mix Aspose.Pdf.LogicalStructure and Aspose.Pdf.Structure namespaces
- Distinctive: line 254
Never modify agents.md files -- they are auto-generated
- Very specific: line 255
Never modify the .csproj template -- it is generated
- Distinctive: line 299
When a type name can resolve to multiple namespaces (especially with Aspose.Pdf, Aspose.Pdf.Drawing, System.IO, and System.Drawing), ALWAYS …
- Distinctive: line 387
Always use fully qualified Aspose.Pdf.Rectangle and Aspose.Pdf.Color to avoid ambiguity with System.Drawing types.
- Distinctive: line 512
All examples are standalone Console Applications
- Distinctive: line 517
Every example must pass these verification steps.
- Very specific: line 556
Ensure input.pdf exists in the same directory (where required)
≈ “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.
Files
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
.csfile is a standalone Console Application -- do not create multi-file projects - All examples must compile and run without errors using
dotnet buildanddotnet 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.jsonunless the task explicitly asks for generator output changes. - For contribution workflow, validation expectations, and pull-request requirements, see
CONTRIBUTING.mdand.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
.csfile - Using deprecated APIs -- check the Aspose.PDF changelog for the current API surface
- Adding NuGet packages beyond
Aspose.PDF-- the.csprojtemplate only includes Aspose.PDF - Modifying shared infrastructure --
.csprojtemplates,agents.mdfiles, CI configs
🚫 Never
See the full Common Mistakes section below for code-level prohibitions with examples.
- Never use
varfor variable declarations - Never use 0-based indexing for
Pages,Annotations, orEmbeddedFiles - Never use unqualified type names for
Rectangle,Color,Path,Image,Matrix,Point - Never use
Aspose.Pdf.Savingnamespace (it does not exist) - Never mix
Aspose.Pdf.LogicalStructureandAspose.Pdf.Structurenamespaces - Never modify
agents.mdfiles -- they are auto-generated - Never modify the
.csprojtemplate -- 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 runProject 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
.csfile 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
CSerror 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, orFileNotFoundException
Common Error Codes
| Code | Meaning | Fix |
CS0104 | Ambiguous type reference | Use fully qualified name (Aspose.Pdf.Rectangle) |
CS1061 | Member does not exist on type | Check API docs for correct property/method |
CS0246 | Type or namespace not found | Add missing using directive |
CS0029 | Cannot convert type | Cast 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
- Navigate to any category folder
- Each .cs file is a standalone Console Application
- Ensure
input.pdfexists in the same directory (where required) - 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
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
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.

