Contributing to TerraPDF
Thank you for taking the time to contribute! This document explains how to get started, what we expect from contributions, and how the release process works.
Table of Contents
- Code of Conduct
- Getting Started
- Project Structure
- Making Changes
- Coding Standards
- Tests
- Submitting a Pull Request
- Reporting Bugs
- Suggesting Features
- Release Process
Code of Conduct
Be respectful, constructive, and welcoming. We will not tolerate harassment or discrimination in any form.
Getting Started
Prerequisites
- .NET 10 SDK (the repository's
global.jsonpins to it, withrollForward: latestMajor; the library itself targets .NET 8, .NET 9, and .NET 10 at runtime) - Git
Clone and Build
git clone https://github.com/sahebansari/TerraPDF.git
cd TerraPDF
dotnet restore
dotnet build
dotnet test
Project Structure
TerraPDF/
âââ src/
â âââ TerraPDF/
â âââ Core/ # Fluent API â descriptors, extension methods, Document entry point
â âââ Drawing/ # PDF rendering â PdfDocument, PdfPage, FontMetrics, image decoders
â âââ Elements/ # Internal layout tree â Column, Row, Table, TextBlock, decorators
â âââ Helpers/ # Public helpers â Color, PageSize, TextStyle, Unit
â âââ Infra/ # Public interfaces â IContainer, IDocument, IComponent
âââ tests/
â âââ TerraPDF.Tests/ # xUnit test projects
âââ samples/
â âââ TerraPDF.Sample/ # Six sample PDFs covering all major features
âââ docs/ # Markdown documentation
âââ .github/workflows/ # CI and publish workflows
âââ Directory.Build.props # Shared MSBuild properties (nullable, warnings, etc.)
âââ .editorconfig # Code style rules
Making Changes
-
Fork the repository and create a branch from
main:git checkout -b feature/my-feature -
Make your changes. Keep commits focused and atomic.
-
Ensure all existing tests still pass and add new tests for any behaviour you introduce or change.
-
Run the full test suite before pushing:
dotnet test -c Release -
Open a Pull Request against
main.
Coding Standards
All standards are enforced automatically by the build:
- Nullable reference types are enabled (
<Nullable>enable</Nullable>) â no nullable warnings are accepted. - Warnings as errors â the build fails on any warning.
.editorconfigâ code style (indentation, naming, var usage, etc.) is enforced at build time via<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>.- XML doc comments are required on all public members.
- Input validation â every public API method that takes user-supplied
arguments must guard them with the appropriate
ArgumentNullException.ThrowIfNull,ArgumentException.ThrowIfNullOrWhiteSpace, orArgumentOutOfRangeException.ThrowIfNegative/ThrowIfNegativeOrZerocall (all available since .NET 8). - No third-party dependencies in the library project â TerraPDF has zero runtime dependencies and this must remain true.
Tests
Tests live in tests/TerraPDF.Tests/ and use xUnit.
| File | What it tests |
|---|---|
DocumentGenerationTests.cs |
Integration â produces valid PDF bytes |
FontMetricsTests.cs |
Unit â glyph-width accuracy against Adobe AFM values |
TextStyleTests.cs |
Unit â TextStyle immutability and merge logic |
ValidationTests.cs |
Unit â every public method throws the right exception on bad input |
BehaviourTests.cs |
Integration â layout, formatting, decorator, and component behaviour |
HighPriorityFeatureTests.cs |
Integration â underline, line-height, hyperlink, per-edge borders |
RoundedBorderTests.cs |
Unit/Integration â RoundedBorder and RoundedBox geometry and validation |
PageBreakTests.cs |
Integration â explicit page-break positioning |
HeaderFirstPageOnlyTests.cs |
Integration â conditional first-page-only header rendering |
Running with coverage
dotnet test -c Release --collect:"XPlat Code Coverage"
Coverage reports (Cobertura XML) are written to TestResults/.
Submitting a Pull Request
- Fill in the PR template with a clear description of what changed and why.
- Reference any related issues (e.g.
Closes #42). - All CI checks must pass before a review is requested.
- At least one maintainer approval is required before merging.
Reporting Bugs
Open a GitHub Issue and include:
- TerraPDF version
- .NET runtime version
- A minimal reproducible code snippet
- The expected vs. actual behaviour
Suggesting Features
Open a GitHub Issue with the
label enhancement. Describe the use-case, not just the solution.
Release Process
Release steps, API key management, and NuGet troubleshooting are maintained in one place to avoid drift â see Publishing TerraPDF for the full, current process. The short version, for context:
- Bump
<Version>insrc/TerraPDF/TerraPDF.csproj. - Update
CHANGELOG.mdâ move items from[Unreleased]to a new versioned section. - Commit and push to
main, then wait for CI to go green. - Create a GitHub Release with a tag matching the version (e.g.
v1.3.0); thepublish.ymlworkflow packs and pushes the.nupkg/.snupkgto nuget.org automatically. - Verify on nuget.org.