Gotenberg.Sharp.API.Client 2.2.2

dotnet add package Gotenberg.Sharp.API.Client --version 2.2.2
NuGet\Install-Package Gotenberg.Sharp.API.Client -Version 2.2.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Gotenberg.Sharp.API.Client" Version="2.2.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Gotenberg.Sharp.API.Client --version 2.2.2
#r "nuget: Gotenberg.Sharp.API.Client, 2.2.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Gotenberg.Sharp.API.Client as a Cake Addin
#addin nuget:?package=Gotenberg.Sharp.API.Client&version=2.2.2

// Install Gotenberg.Sharp.API.Client as a Cake Tool
#tool nuget:?package=Gotenberg.Sharp.API.Client&version=2.2.2

gotenberg icon Gotenberg.Sharp.Api.Client

NuGet version Downloads Build status

⭐ For Gotenberg v7 & v8 ⭐

.NET C# Client for interacting with the Gotenberg v7 & v8 micro-service's API. Gotenberg is a Docker-powered stateless API for converting & merging HTML, Markdown and Office documents to PDF. The client supports a configurable Polly retry policy with exponential backoff for handling transient exceptions.

Getting Started

Pull the image from

> docker pull gotenberg/gotenberg:latest

Create & start a container

docker run --name gotenbee8x --rm -p 3000:3000 gotenberg/gotenberg:latest gotenberg --api-timeout=1800s --log-level=debug

.NET Core Project Setup

Install nuget package into your project

PM> Install-Package Gotenberg.Sharp.Api.Client

Note: Use v1.x nugets for Gotenberg v6.


  "GotenbergSharpClient": {
    "ServiceUrl": "http://localhost:3000",
    "HealthCheckUrl": "http://localhost:3000/health",
    "RetryPolicy": {
      "Enabled": true,
      "RetryCount": 4,
      "BackoffPower": 1.5,
      "LoggingEnabled": true

Configure Services In Startup.cs

public void ConfigureServices(IServiceCollection services)

Using GotenbergSharpClient

See the linqPad folder for complete examples.

Html To Pdf

With embedded assets:

 public async Task<ActionResult> HtmlToPdf([FromServices] GotenbergSharpClient sharpClient)
     var builder = new HtmlRequestBuilder()
         .AddDocument(doc => 
         ).WithDimensions(dims =>
         }).WithAsyncAssets(async assets => assets.AddItem("some-image.jpg", await GetImageBytes()));

     var req = await builder.BuildAsync();

     var result = await sharpClient.HtmlToPdfAsync(req);

     return this.File(result, "application/pdf", "gotenbergFromHtml.pdf");

Url To Pdf

Url to Pdf with custom page range, header & footer:

public async Task<Stream> CreateFromUrl(string headerPath, string footerPath)
	var builder = new UrlRequestBuilder()
		.ConfigureRequest(config =>
			doc => doc.SetHeader(await File.ReadAllTextAsync(headerPath))
				  .SetFooter(await File.ReadAllBytesAsync(footerPath)
		)).WithDimensions(dims =>

	var request = await builder.BuildAsync();
	return await _sharpClient.UrlToPdfAsync(request);

Merge Office Docs

Merges office documents and configures the request time-out:

public async Task<Stream> DoOfficeMerge(string sourceDirectory)
	var builder = new MergeOfficeBuilder()
		.WithAsyncAssets(async a => a.AddItems(await GetDocsAsync(sourceDirectory)));

	var request = await builder.BuildAsync();
	return await _sharpClient.MergeOfficeDocsAsync(request);

Markdown to Pdf

Markdown to Pdf conversion with embedded assets:

public async Task<Stream> CreateFromMarkdown()
	var builder = new HtmlRequestBuilder()
			doc => doc.SetHeader(await this.GetHeaderAsync())
				  .SetBody(await GetBodyAsync())
				  .SetFooter(await GetFooterAsync())
		).WithDimensions(dims =>
			a => a.AddItems(await GetMarkdownAssets())

	var request = await builder.BuildAsync();
	return await _sharpClient.HtmlToPdfAsync(request);


All request types support webhooks

 public async Task SendUrlToWebhookEndpoint(string headerPath, string footerPath)
     var builder = new UrlRequestBuilder()
         .ConfigureRequest(reqBuilder =>
             reqBuilder.AddWebhook(hook =>
                         .AddExtraHeader("custom-header", "value");
             b => b.SetHeader(await System.IO.File.ReadAllTextAsync(headerPath))
                   .SetFooter(await System.IO.File.ReadAllBytesAsync(footerPath))
         ).WithDimensions(dimBuilder =>

     var request = await builder.BuildAsync();

     await _sharpClient.FireWebhookAndForgetAsync(request);

Merge 15 Urls to one pdf

Builds a 30 page pdf by merging the front two pages of 15 news sites. Takes about a minute to complete

public async Task<Stream> CreateWorldNewsSummary()
    var sites = new[]
            "", "", "",
            "", "", "",
            "", "", "",
            "", "",
            "", "",
            "", ""
        .Select(u => new Uri(u));

    var builders = CreateBuilders(sites);
    var requests = builders.Select(b => b.Build());

    return await ExecuteRequestsAndMerge(requests);

IEnumerable<UrlRequestBuilder> CreateBuilders(IEnumerable<Uri> uris)
    foreach (var uri in uris)
        yield return new UrlRequestBuilder()
            .ConfigureRequest(req => { req.SetPageRanges("1-2"); })
            .AddHeaderFooter(docBuilder =>
                docBuilder.SetHeader(GetHeadFoot(uri.Host.Replace("www.", string.Empty).ToUpper()))
            .WithDimensions(dimBuilder =>

    static string GetHeadFoot(string heading)
        => "<html><head> <style> body { font-size: 8rem; } h1 { margin-left: auto; margin-right: auto; } </style></head><body><h1>" +
           heading + "</h1></body></html>";

async Task<Stream> ExecuteRequestsAndMerge(IEnumerable<UrlRequest> requests)
    var tasks = requests.Select(r => _sharpClient.UrlToPdfAsync(r));
    var results = await Task.WhenAll(tasks);

    var mergeBuilder = new MergeBuilder()
        .WithAssets(b => { 
            b.AddItems(results.Select((r, i) => KeyValuePair.Create($"{i}.pdf", r))); 

    var request = mergeBuilder.Build();
    return await _sharpClient.MergePdfsAsync(request);
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.2 13,539 1/30/2024
2.1.1 167,987 10/1/2022
2.0.2 41,788 8/30/2022
2.0.1 899 8/30/2022
2.0.0-alpha0002 29,811 3/3/2022
1.2.0 98,029 5/11/2021
1.0.0 109,978 6/3/2020
0.9.51 82,849 3/22/2020
0.9.37 27,862 2/11/2020
0.9.26 1,842 12/19/2019
0.9.2 6,331 11/21/2019

v2.2 - Added 'SkipNetworkIdle' flag support (Gotenberg v8+ Only). Thank you for the PR @guillaumeduhr! Upgraded nugets to latest. Added .NET 7.0 support.
v2.1 - Added Trace Support. Fixed extra webhook header support.
v2.0 - Upgraded to support Gotenberg v7 -- this version no longer works with Gotenberg v6.