Home
Softono
GotenbergSharpApiClient

GotenbergSharpApiClient

Open source Apache-2.0 C#
205
Stars
24
Forks
0
Issues
9
Watchers
2 months
Last Commit

About GotenbergSharpApiClient

A .NET C client for the Gotenberg API that enables document conversion and PDF operations within .NET applications. Supports converting HTML, URLs, and Office documents to PDF using Chromium and LibreOffice engines. Features include HTML to PDF conversion with custom page properties and headers, screenshots of web content as PNG, JPEG, or WebP, and Office document conversion supporting over 100 formats. Provides comprehensive PDF manipulation capabilities including merge, flatten, rotate, split, encrypt, watermark, and stamp operations. Supports PDF/A and PDF/UA compliance, metadata handling, and webhook-based async generation. Includes configurable Polly retry policies with exponential backoff for resilient API communication. Compatible with Gotenberg v7 and v8, designed for dependency injection, and targets .NET 10, 9, 8, and netstandard 2.x.

Platforms

Web Self-hosted Windows iOS

Languages

C#

Links

Gotenberg Sharp API Client

NuGet version Downloads Build status

.NET C# client for Gotenberg v7 & v8 — a Docker-powered stateless API for converting & merging HTML, Markdown, and Office documents to PDF. Includes a configurable Polly retry policy with exponential backoff.

v3.0.0 — Screenshots, standalone PDF operations (flatten/rotate/split/encrypt), cross-cutting watermark & stamp options, LibreOffice conversion options, .NET 10/9/8 + netstandard 2.x. See CHANGES.MD for details.

Features

  • HTML/URL to PDF with Chromium (page properties, headers/footers, cookies, wait conditions)
  • Screenshots of HTML or URLs as PNG, JPEG, or WebP
  • Office to PDF via LibreOffice (100+ formats, image compression, watermarks)
  • PDF Manipulation — merge, flatten, rotate, split, encrypt, watermark, stamp
  • PDF/A & PDF/UA compliance, metadata read/write
  • Webhooks for async PDF generation
  • DI-Ready with Polly retry policies

Quick Start

docker run --rm -p 3000:3000 gotenberg/gotenberg:latest
dotnet add package Gotenberg.Sharp.Api.Client
// Startup.cs
services.AddOptions<GotenbergSharpClientOptions>()
    .Bind(Configuration.GetSection("GotenbergSharpClient"));
services.AddGotenbergSharpClient();

HTML to PDF

var builder = new HtmlRequestBuilder()
    .AddDocument(doc => doc.SetBody("<html><body><h1>Hello PDF!</h1></body></html>"))
    .WithPageProperties(pp => pp.UseChromeDefaults());

var result = await sharpClient.HtmlToPdfAsync(builder);

Screenshot

var builder = new ScreenshotHtmlRequestBuilder()
    .AddDocument(doc => doc.SetBody("<html><body><h1>Screenshot!</h1></body></html>"))
    .WithScreenshotProperties(p => p.SetSize(1280, 720).SetFormat(ScreenshotFormat.Png));

var imageStream = await sharpClient.ScreenshotHtmlAsync(builder);

Office to PDF

var builder = new MergeOfficeBuilder()
    .WithAsyncAssets(async a => a.AddItems(await GetDocsAsync(sourceDir)))
    .SetLibreOfficeOptions(o => o.SetQuality(85).SetExportBookmarks())
    .SetPdfOutputOptions(o => o.SetPdfFormat(PdfFormat.A2b));

var result = await sharpClient.MergeOfficeDocsAsync(builder);

PDF Operations

// Rotate
using var rotated = await sharpClient.ExecutePdfEngineAsync(
    PdfEngineBuilders.Rotate(90).WithPdfs(a => a.AddItem("doc.pdf", bytes)));

// Encrypt
using var encrypted = await sharpClient.ExecutePdfEngineAsync(
    PdfEngineBuilders.Encrypt("reader123", "admin456").WithPdfs(a => a.AddItem("doc.pdf", bytes)));

// Watermark (inline, on any conversion)
var builder = new HtmlRequestBuilder()
    .AddDocument(doc => doc.SetBody(html))
    .SetWatermarkOptions(w => w.SetTextWatermark("DRAFT"));

Documentation

See the full documentation for:

Examples

See the examples folder for complete working console applications.

Release History

See CHANGES.MD for the full release history.

Star History

Star History Chart

License

Apache 2.0