Skip to content

Commit 5463769

Browse files
committed
Merge branch 'release/2.0.0' into master
2 parents a3b0e99 + 306a67e commit 5463769

105 files changed

Lines changed: 4522 additions & 731 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*.cs]
2+
3+
# IDE0042: Deconstruct variable declaration
4+
dotnet_diagnostic.IDE0042.severity = none

.github/workflows/deploy.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Build and Push to Nuget
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
with:
13+
fetch-depth: 0
14+
15+
- name: Setup Dotnet
16+
uses: actions/setup-dotnet@v1
17+
with:
18+
dotnet-version: 6.0.100
19+
20+
- name: Install GitVersion
21+
uses: gittools/actions/gitversion/setup@v0.9.7
22+
with:
23+
versionSpec: '5.x'
24+
25+
- name: GitVersion
26+
id: gitversion
27+
uses: gittools/actions/gitversion/execute@v0.9.7
28+
with:
29+
useConfigFile: true
30+
31+
- name: Pack
32+
run: dotnet pack -c Release --version-suffix ${{ steps.gitversion.outputs.nuGetVersion }}
33+
34+
- name: Publish
35+
if: github.event_name != 'pull_request' && (github.ref_name == 'master')
36+
run: |
37+
dotnet nuget push **/*.nupkg --source 'https://api.nuget.org/v3/index.json' --skip-duplicate -k ${{ secrets.NUGETKEY }} --no-symbols 1

GitVersion.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mode: Mainline
2+
branches: {}
3+
ignore:
4+
sha: []
5+
merge-message-formats: {}

GotenbergSharpApiClient.sln

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.30011.22
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.32112.339
55
MinimumVisualStudioVersion = 15.0.26124.0
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gotenberg.Sharp.Api.Client", "lib\Gotenberg.Sharp.Api.Client.csproj", "{75F783A4-9392-412F-9DFE-00EE89527C10}"
77
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FE638D0D-6A76-4BF4-AF06-D8AAB9726723}"
9+
ProjectSection(SolutionItems) = preProject
10+
.editorconfig = .editorconfig
11+
EndProjectSection
12+
EndProject
813
Global
914
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1015
Debug|Any CPU = Debug|Any CPU
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
22
<s:Boolean x:Key="/Default/UserDictionary/Words/=Backoff/@EntryIndexedValue">True</s:Boolean>
3+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Consts/@EntryIndexedValue">True</s:Boolean>
34
<s:Boolean x:Key="/Default/UserDictionary/Words/=deliverables/@EntryIndexedValue">True</s:Boolean>
5+
<s:Boolean x:Key="/Default/UserDictionary/Words/=epub/@EntryIndexedValue">True</s:Boolean>
6+
<s:Boolean x:Key="/Default/UserDictionary/Words/=fodg/@EntryIndexedValue">True</s:Boolean>
7+
<s:Boolean x:Key="/Default/UserDictionary/Words/=fodp/@EntryIndexedValue">True</s:Boolean>
8+
<s:Boolean x:Key="/Default/UserDictionary/Words/=fods/@EntryIndexedValue">True</s:Boolean>
49
<s:Boolean x:Key="/Default/UserDictionary/Words/=fodt/@EntryIndexedValue">True</s:Boolean>
510
<s:Boolean x:Key="/Default/UserDictionary/Words/=Gotenberg/@EntryIndexedValue">True</s:Boolean>
11+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Gotenberg_0027s/@EntryIndexedValue">True</s:Boolean>
612
<s:Boolean x:Key="/Default/UserDictionary/Words/=Libre/@EntryIndexedValue">True</s:Boolean>
713
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pdfs/@EntryIndexedValue">True</s:Boolean>
14+
<s:Boolean x:Key="/Default/UserDictionary/Words/=potm/@EntryIndexedValue">True</s:Boolean>
815
<s:Boolean x:Key="/Default/UserDictionary/Words/=Rpcc/@EntryIndexedValue">True</s:Boolean>
16+
<s:Boolean x:Key="/Default/UserDictionary/Words/=suppressions/@EntryIndexedValue">True</s:Boolean>
917
<s:Boolean x:Key="/Default/UserDictionary/Words/=unoconv/@EntryIndexedValue">True</s:Boolean>
1018
<s:Boolean x:Key="/Default/UserDictionary/Words/=Webhook/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

README.md

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
⭐ For Gotenberg v7+. Beta⭐
2+
13
# <img src="https://github.com/ChangemakerStudios/GotenbergSharpApiClient/raw/master/lib/Resources/gotenbergSharpClient.PNG" width="24" height="24" /> Gotenberg.Sharp.Api.Client
24

3-
[![NuGet version](https://badge.fury.io/nu/Gotenberg.Sharp.Api.Client.svg)](https://badge.fury.io/nu/Gotenberg.Sharp.Api.Client) [![Build status](https://ci.appveyor.com/api/projects/status/s8lvj93xewlsylxh/branch/master?svg=true)](https://ci.appveyor.com/project/Jaben/gotenbergsharpapiclient/branch/master) [![Downloads](https://img.shields.io/nuget/dt/Gotenberg.Sharp.API.Client.svg?logo=nuget&color=purple)](https://www.nuget.org/packages/Gotenberg.Sharp.API.Client)
5+
[![NuGet version](https://badge.fury.io/nu/Gotenberg.Sharp.Api.Client.svg)](https://badge.fury.io/nu/Gotenberg.Sharp.Api.Client) [![Build status](https://ci.appveyor.com/api/projects/status/s8lvj93xewlsylxh?svg=true)](https://ci.appveyor.com/project/Jaben/gotenbergsharpapiclient) [![Downloads](https://img.shields.io/nuget/dt/Gotenberg.Sharp.API.Client.svg?logo=nuget&color=purple)](https://www.nuget.org/packages/Gotenberg.Sharp.API.Client)
6+
7+
.NET C# Client for interacting with the [Gotenberg](https://gotenberg.dev/) micro-service's API. [Gotenberg](https://github.com/gotenberg/gotenberg) is a [Docker-powered stateless API](https://hub.docker.com/r/gotenberg/gotenberg/) for converting & merging HTML, Markdown and Office documents to PDF. The client supports a configurable [Polly](http://www.thepollyproject.org/) **retry policy** with exponential backoff for handling transient exceptions.
48

5-
.NET C# Client for interacting with the [Gotenberg](https://thecodingmachine.github.io/gotenberg) micro-service's API. [Gotenberg](https://github.com/thecodingmachine/gotenberg) is a [Docker-powered stateless API](https://hub.docker.com/r/thecodingmachine/gotenberg) for converting & merging HTML, Markdown and Office documents to PDF. The client supports a configurable [Polly](http://www.thepollyproject.org/) **retry policy** with exponential backoff for handling transient exceptions.
9+
*As of version [2.0.0-alpha0002](https://www.nuget.org/packages/Gotenberg.Sharp.API.Client/2.0.0-alpha0002#supportedframeworks-tab) Gotenberg.Sharp.API.Client targets net6.0, net5.0; netstandard 2.0 and 2.1*
610

711
# Getting Started
812
*Pull the image from dockerhub.com*
913
```powershell
10-
> docker pull thecodingmachine/gotenberg:latest
14+
> docker pull gotenberg/gotenberg:latest
1115
```
1216
*Create & start a container*
1317
```powershell
14-
docker run --name gotenbee -e DEFAULT_WAIT_TIMEOUT=1800 -e MAXIMUM_WAIT_TIMEOUT=1800 -e LOG_LEVEL=DEBUG -p:3000:3000 "thecodingmachine/gotenberg:latest"
18+
docker run --name gotenbee7x --rm -p 3000:3000 gotenberg/gotenberg:latest gotenberg --api-timeout=1800s --log-level=debug
1519
```
1620
# .NET Core Project Setup
1721
*Install nuget package into your project*
@@ -22,7 +26,7 @@ PM> Install-Package Gotenberg.Sharp.Api.Client
2226
```json
2327
"GotenbergSharpClient": {
2428
"ServiceUrl": "http://localhost:3000",
25-
"HealthCheckUrl": "http://localhost:3000/ping",
29+
"HealthCheckUrl": "http://localhost:3000/health",
2630
"RetryPolicy": {
2731
"Enabled": true,
2832
"RetryCount": 4,
@@ -44,9 +48,11 @@ public void ConfigureServices(IServiceCollection services)
4448
}
4549

4650
```
47-
# Using GotenbergSharpClient
51+
# Using GotenbergSharpClient.
4852
*See the [linqPad folder](linqpad/)* for complete examples.
4953

54+
### Note: Samples below are currently stale. Linqpad scripts are fresh.
55+
5056
## Html To Pdf
5157
*With embedded assets:*
5258

@@ -62,12 +68,7 @@ public void ConfigureServices(IServiceCollection services)
6268
dims.SetPaperSize(PaperSizes.A3)
6369
.SetMargins(Margins.None)
6470
.SetScale(.99);
65-
}).WithAsyncAssets(async assets => assets.AddItem("some-image.jpg", await GetImageBytes()))
66-
.ConfigureRequest(config =>
67-
{
68-
config.ChromeRpccBufferSize(1024)
69-
.PageRanges("1");
70-
});
71+
}).WithAsyncAssets(async assets => assets.AddItem("some-image.jpg", await GetImageBytes()));
7172

7273
var req = await builder.BuildAsync();
7374

@@ -87,7 +88,7 @@ public async Task<Stream> CreateFromUrl(string headerPath, string footerPath)
8788
.SetUrl("https://www.cnn.com")
8889
.ConfigureRequest(config =>
8990
{
90-
config.PageRanges("1-2").ChromeRpccBufferSize(1048576);
91+
config.PageRanges("1-2");
9192
})
9293
.AddAsyncHeaderFooter(async
9394
doc => doc.SetHeader(await File.ReadAllTextAsync(headerPath))
@@ -111,11 +112,7 @@ public async Task<Stream> CreateFromUrl(string headerPath, string footerPath)
111112
public async Task<Stream> DoOfficeMerge(string sourceDirectory)
112113
{
113114
var builder = new MergeOfficeBuilder()
114-
.WithAsyncAssets(async a => a.AddItems(await GetDocsAsync(sourceDirectory)))
115-
.ConfigureRequest(config =>
116-
{
117-
config.TimeOut(100);
118-
});
115+
.WithAsyncAssets(async a => a.AddItems(await GetDocsAsync(sourceDirectory)));
119116

120117
var request = await builder.BuildAsync();
121118
return await _sharpClient.MergeOfficeDocsAsync(request);
@@ -138,10 +135,7 @@ public async Task<Stream> CreateFromMarkdown()
138135
dims.UseChromeDefaults().LandScape().SetScale(.90);
139136
}).WithAsyncAssets(async
140137
a => a.AddItems(await GetMarkdownAssets())
141-
).ConfigureRequest(req =>
142-
{
143-
req.ChromeRpccBufferSize(1048555);
144-
});
138+
));
145139

146140
var request = await builder.BuildAsync();
147141
return await _sharpClient.HtmlToPdfAsync(request);
@@ -163,12 +157,11 @@ public async Task<Stream> CreateFromMarkdown()
163157
.SetUrl("http://host.docker.internal:5000/api/your/webhookReceiver")
164158
.AddRequestHeader("custom-header", "value");
165159
})
166-
.PageRanges("1-2")
167-
.ChromeRpccBufferSize(1048576);
160+
.PageRanges("1-2");
168161
})
169162
.AddAsyncHeaderFooter(async
170-
docBuilder => docBuilder.SetHeader(await System.IO.File.ReadAllTextAsync(headerPath))
171-
.SetFooter(await System.IO.File.ReadAllBytesAsync(footerPath))
163+
b => b.SetHeader(await System.IO.File.ReadAllTextAsync(headerPath))
164+
.SetFooter(await System.IO.File.ReadAllBytesAsync(footerPath))
172165
).WithDimensions(dimBuilder =>
173166
{
174167
dimBuilder.SetPaperSize(PaperSizes.A4)
@@ -240,11 +233,11 @@ async Task<Stream> ExecuteRequestsAndMerge(IEnumerable<UrlRequest> requests)
240233
var results = await Task.WhenAll(tasks);
241234

242235
var mergeBuilder = new MergeBuilder()
243-
.WithAssets(b =>
244-
{ b.AddItems(results.Select((r, i) => KeyValuePair.Create($"{i}.pdf", r))); }
245-
).ConfigureRequest(b => b.TimeOut(1799));
236+
.WithAssets(b => {
237+
b.AddItems(results.Select((r, i) => KeyValuePair.Create($"{i}.pdf", r)));
238+
});
246239

247240
var request = mergeBuilder.Build();
248241
return await _sharpClient.MergePdfsAsync(request);
249242
}
250-
```
243+
```

appveyor.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
version: 1.0.{build}
1+
version: 2.0.{build}
22

3-
image: Visual Studio 2019
3+
image: Visual Studio 2022
4+
5+
branches:
6+
except:
7+
- /feature\/.+/
48

59
configuration: Release
610

lib/Domain/Builders/BaseBuilder.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
1-
using Gotenberg.Sharp.API.Client.Domain.Requests;
1+
using System;
2+
3+
using Gotenberg.Sharp.API.Client.Domain.Builders.Faceted;
4+
using Gotenberg.Sharp.API.Client.Domain.Requests;
5+
using Gotenberg.Sharp.API.Client.Domain.Requests.Facets;
6+
7+
using JetBrains.Annotations;
28

39
namespace Gotenberg.Sharp.API.Client.Domain.Builders
410
{
5-
public abstract class BaseBuilder<TRequest> where TRequest : RequestBase
11+
public abstract class BaseBuilder<TRequest, TBuilder>
12+
where TRequest : RequestBase
13+
where TBuilder : BaseBuilder<TRequest, TBuilder>
614
{
715
protected virtual TRequest Request { get; set; }
816

917
protected const string CallBuildAsyncErrorMessage = "Request has asynchronous items. Call BuildAsync instead.";
18+
19+
[PublicAPI]
20+
public TBuilder ConfigureRequest(Action<ConfigBuilder> action)
21+
{
22+
if (action == null) throw new ArgumentNullException(nameof(action));
23+
action(new ConfigBuilder(this.Request));
24+
return (TBuilder) this;
25+
}
26+
27+
[PublicAPI]
28+
public TBuilder ConfigureRequest(RequestConfig config)
29+
{
30+
this.Request.Config = config ?? throw new ArgumentNullException(nameof(config));
31+
return (TBuilder) this;
32+
}
1033
}
1134
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
5+
using Gotenberg.Sharp.API.Client.Domain.Builders.Faceted;
6+
using Gotenberg.Sharp.API.Client.Domain.Requests;
7+
using Gotenberg.Sharp.API.Client.Domain.Requests.Facets;
8+
9+
using JetBrains.Annotations;
10+
11+
namespace Gotenberg.Sharp.API.Client.Domain.Builders;
12+
13+
public abstract class BaseChromiumBuilder<TRequest, TBuilder> : BaseBuilder<TRequest, TBuilder>
14+
where TRequest : ChromeRequest
15+
where TBuilder : BaseChromiumBuilder<TRequest, TBuilder>
16+
{
17+
protected readonly List<Task> AsyncTasks = new List<Task>();
18+
19+
[PublicAPI]
20+
public TBuilder WithDimensions(Action<DimensionBuilder> action)
21+
{
22+
if (action == null) throw new ArgumentNullException(nameof(action));
23+
24+
action(new DimensionBuilder(this.Request));
25+
return (TBuilder) this;
26+
}
27+
28+
[PublicAPI]
29+
public TBuilder WithDimensions(Dimensions dimensions)
30+
{
31+
this.Request.Dimensions = dimensions ?? throw new ArgumentNullException(nameof(dimensions));
32+
return (TBuilder) this;
33+
}
34+
35+
[PublicAPI]
36+
public TBuilder WithAssets(Action<AssetBuilder> action)
37+
{
38+
if (action == null) throw new ArgumentNullException(nameof(action));
39+
action(new AssetBuilder(this.Request));
40+
return (TBuilder) this;
41+
}
42+
43+
[PublicAPI]
44+
public TBuilder WithAsyncAssets(Func<AssetBuilder, Task> asyncAction)
45+
{
46+
if (asyncAction == null) throw new ArgumentNullException(nameof(asyncAction));
47+
this.AsyncTasks.Add(asyncAction(new AssetBuilder(this.Request)));
48+
return (TBuilder) this;
49+
}
50+
51+
[PublicAPI]
52+
public TBuilder SetConversionBehaviors(Action<HtmlConversionBehaviorBuilder> action)
53+
{
54+
if (action == null) throw new ArgumentNullException(nameof(action));
55+
action(new HtmlConversionBehaviorBuilder(this.Request));
56+
return (TBuilder) this;
57+
}
58+
59+
[PublicAPI]
60+
public TBuilder SetConversionBehaviors(HtmlConversionBehaviors behaviors)
61+
{
62+
this.Request.ConversionBehaviors = behaviors ?? throw new ArgumentNullException(nameof(behaviors));
63+
return (TBuilder) this;
64+
}
65+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
5+
using Gotenberg.Sharp.API.Client.Domain.Builders.Faceted;
6+
using Gotenberg.Sharp.API.Client.Domain.Requests;
7+
8+
using JetBrains.Annotations;
9+
10+
namespace Gotenberg.Sharp.API.Client.Domain.Builders;
11+
12+
public abstract class BaseMergeBuilder<TRequest, TBuilder> : BaseBuilder<TRequest, TBuilder>
13+
where TRequest : RequestBase
14+
where TBuilder : BaseMergeBuilder<TRequest, TBuilder>
15+
{
16+
protected readonly List<Task> AsyncTasks = new List<Task>();
17+
18+
/// <summary>
19+
/// This tells gotenberg to have OfficeLibre perform the conversion.
20+
/// If you set <see cref="MergeOfficeRequest.UseNativePdfFormat"/> to true
21+
/// then gotenberg will hand the work off to unoconv to do the work
22+
/// </summary>
23+
[PublicAPI]
24+
public TBuilder SetPdfFormat(PdfFormats format)
25+
{
26+
this.Request.Format = format;
27+
return (TBuilder) this;
28+
}
29+
30+
[PublicAPI]
31+
public TBuilder WithAssets(Action<AssetBuilder> action)
32+
{
33+
if (action == null) throw new ArgumentNullException(nameof(action));
34+
action(new AssetBuilder(this.Request));
35+
return (TBuilder) this;
36+
}
37+
38+
[PublicAPI]
39+
public TBuilder WithAsyncAssets(Func<AssetBuilder, Task> asyncAction)
40+
{
41+
if (asyncAction == null) throw new ArgumentNullException(nameof(asyncAction));
42+
this.AsyncTasks.Add(asyncAction(new AssetBuilder(this.Request)));
43+
return (TBuilder) this;
44+
}
45+
}

0 commit comments

Comments
 (0)