Skip to content

Commit 6f06b85

Browse files
committed
Moving "/lib" to "/src"
1 parent 490797c commit 6f06b85

85 files changed

Lines changed: 1264 additions & 185 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.

GotenbergSharpApiClient.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.0.32112.339
55
MinimumVisualStudioVersion = 15.0.26124.0
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gotenberg.Sharp.Api.Client", "lib\Gotenberg.Sharp.Api.Client.csproj", "{75F783A4-9392-412F-9DFE-00EE89527C10}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gotenberg.Sharp.Api.Client", "src\Gotenberg.Sharp.Api.Client\Gotenberg.Sharp.Api.Client.csproj", "{75F783A4-9392-412F-9DFE-00EE89527C10}"
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FE638D0D-6A76-4BF4-AF06-D8AAB9726723}"
99
ProjectSection(SolutionItems) = preProject

appveyor.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

lib/Domain/Builders/BaseBuilder.cs renamed to src/Gotenberg.Sharp.Api.Client/Domain/Builders/BaseBuilder.cs

File renamed without changes.

lib/Domain/Builders/BaseChromiumBuilder.cs renamed to src/Gotenberg.Sharp.Api.Client/Domain/Builders/BaseChromiumBuilder.cs

File renamed without changes.

lib/Domain/Builders/BaseMergeBuilder.cs renamed to src/Gotenberg.Sharp.Api.Client/Domain/Builders/BaseMergeBuilder.cs

File renamed without changes.

lib/Domain/Builders/Faceted/AssetBuilder.cs renamed to src/Gotenberg.Sharp.Api.Client/Domain/Builders/Faceted/AssetBuilder.cs

File renamed without changes.

lib/Domain/Builders/Faceted/ConfigBuilder.cs renamed to src/Gotenberg.Sharp.Api.Client/Domain/Builders/Faceted/ConfigBuilder.cs

File renamed without changes.

lib/Domain/Builders/Faceted/ConversionPdfFormats.cs renamed to src/Gotenberg.Sharp.Api.Client/Domain/Builders/Faceted/ConversionPdfFormats.cs

File renamed without changes.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Copyright 2019-2025 Chris Mohan, Jaben Cargman
2+
// and GotenbergSharpApiClient Contributors
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
namespace Gotenberg.Sharp.API.Client.Domain.Builders.Faceted;
17+
18+
/// <summary>
19+
/// Note: If you don't specify any dimensions the client sets them to Chrome's defaults
20+
/// </summary>
21+
public sealed class DocumentBuilder
22+
{
23+
private readonly FullDocument _content;
24+
25+
private readonly Action<bool> _setContainsMarkdown;
26+
27+
public DocumentBuilder(FullDocument content, Action<bool> setContainsMarkdown)
28+
{
29+
this._content = content ?? throw new ArgumentNullException(nameof(content));
30+
this._setContainsMarkdown = setContainsMarkdown;
31+
}
32+
33+
#region body
34+
35+
[Obsolete("Use SetContainsMarkdown()")]
36+
public DocumentBuilder ContainsMarkdown(bool containsMarkdown = true)
37+
{
38+
this._setContainsMarkdown(containsMarkdown);
39+
return this;
40+
}
41+
42+
public DocumentBuilder SetContainsMarkdown(bool containsMarkdown = true)
43+
{
44+
this._setContainsMarkdown(containsMarkdown);
45+
return this;
46+
}
47+
48+
public DocumentBuilder SetBody(ContentItem body)
49+
{
50+
this._content.Body = body ?? throw new ArgumentNullException(nameof(body));
51+
return this;
52+
}
53+
54+
public DocumentBuilder SetBody(string body)
55+
{
56+
return this.SetBody(new ContentItem(body));
57+
}
58+
59+
public DocumentBuilder SetBody(byte[] body)
60+
{
61+
return this.SetBody(new ContentItem(body));
62+
}
63+
64+
public DocumentBuilder SetBody(Stream body)
65+
{
66+
return this.SetBody(new ContentItem(body));
67+
}
68+
69+
#endregion
70+
71+
#region header
72+
73+
public DocumentBuilder SetHeader(ContentItem header)
74+
{
75+
this._content.Header = header ?? throw new ArgumentNullException(nameof(header));
76+
return this;
77+
}
78+
79+
public DocumentBuilder SetHeader(string header)
80+
{
81+
return this.SetHeader(new ContentItem(header));
82+
}
83+
84+
public DocumentBuilder SetHeader(byte[] header)
85+
{
86+
return this.SetHeader(new ContentItem(header));
87+
}
88+
89+
public DocumentBuilder SetHeader(Stream header)
90+
{
91+
return this.SetHeader(new ContentItem(header));
92+
}
93+
94+
#endregion
95+
96+
#region footer
97+
98+
public DocumentBuilder SetFooter(ContentItem footer)
99+
{
100+
this._content.Footer = footer ?? throw new ArgumentNullException(nameof(footer));
101+
return this;
102+
}
103+
104+
public DocumentBuilder SetFooter(string footer)
105+
{
106+
return this.SetFooter(new ContentItem(footer));
107+
}
108+
109+
public DocumentBuilder SetFooter(byte[] footer)
110+
{
111+
return this.SetFooter(new ContentItem(footer));
112+
}
113+
114+
public DocumentBuilder SetFooter(Stream footer)
115+
{
116+
return this.SetFooter(new ContentItem(footer));
117+
}
118+
119+
#endregion
120+
}
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
// Copyright 2019-2025 Chris Mohan, Jaben Cargman
2+
// and GotenbergSharpApiClient Contributors
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
using Newtonsoft.Json.Linq;
17+
18+
namespace Gotenberg.Sharp.API.Client.Domain.Builders.Faceted;
19+
20+
public sealed class HtmlConversionBehaviorBuilder
21+
{
22+
private readonly HtmlConversionBehaviors _htmlConversionBehaviors;
23+
24+
internal HtmlConversionBehaviorBuilder(HtmlConversionBehaviors htmlConversionBehaviors)
25+
{
26+
_htmlConversionBehaviors = htmlConversionBehaviors;
27+
}
28+
29+
/// <summary>
30+
/// Sets the wait duration when loading an HTML document before converting it to PDF
31+
/// </summary>
32+
/// <param name="seconds"></param>
33+
/// <returns></returns>
34+
/// <remarks>Prefer <see cref="SetBrowserWaitExpression" /> over waitDelay.</remarks>
35+
public HtmlConversionBehaviorBuilder SetBrowserWaitDelay(int seconds)
36+
{
37+
_htmlConversionBehaviors.WaitDelay = $"{seconds}s";
38+
39+
return this;
40+
}
41+
42+
/// <summary>
43+
/// Sets a java-script expression to wait before converting an HTML document to PDF until it returns true
44+
/// </summary>
45+
/// <param name="expression">The expression to set</param>
46+
/// <returns></returns>
47+
/// <remarks>Prefer this option over waitDelay.</remarks>
48+
/// <example>SetBrowserWaitExpression("window.status === 'ready'")</example>
49+
/// <exception cref="InvalidOperationException"></exception>
50+
public HtmlConversionBehaviorBuilder SetBrowserWaitExpression(string expression)
51+
{
52+
if (expression.IsNotSet())
53+
{
54+
throw new InvalidOperationException("expression is not set");
55+
}
56+
57+
_htmlConversionBehaviors.WaitForExpression = expression;
58+
59+
return this;
60+
}
61+
62+
/// <summary>
63+
/// Overrides the default User-Agent extraHeaders
64+
/// </summary>
65+
/// <param name="userAgent"></param>
66+
/// <returns></returns>
67+
/// <exception cref="InvalidOperationException"></exception>
68+
[Obsolete("Deprecated in Gotenberg v8+")]
69+
public HtmlConversionBehaviorBuilder SetUserAgent(string userAgent)
70+
{
71+
if (userAgent.IsNotSet())
72+
{
73+
throw new InvalidOperationException("headerName is not set");
74+
}
75+
76+
_htmlConversionBehaviors.UserAgent = userAgent;
77+
78+
return this;
79+
}
80+
81+
/// <summary>
82+
/// Sets extra HTTP headers that Chromium will send when loading the HTML
83+
/// </summary>
84+
/// <param name="headerName"></param>
85+
/// <param name="headerValue"></param>
86+
/// <returns></returns>
87+
/// <exception cref="InvalidOperationException"></exception>
88+
/// <exception cref="JsonReaderException"></exception>
89+
public HtmlConversionBehaviorBuilder AddAdditionalHeaders(string headerName, string headerValue)
90+
{
91+
var header = string.Format("{0}{2}{1}", "{", "}", $"{'"'}{headerName}{'"'} : {'"'}{headerValue}{'"'}");
92+
93+
return AddAdditionalHeaders(JObject.Parse(header));
94+
}
95+
96+
/// <summary>
97+
/// Sets extra HTTP headers that Chromium will send when loading the HTML
98+
/// </summary>
99+
/// <param name="extraHeaders"></param>
100+
/// <returns></returns>
101+
/// <exception cref="InvalidOperationException"></exception>
102+
public HtmlConversionBehaviorBuilder AddAdditionalHeaders(JObject extraHeaders)
103+
{
104+
if (extraHeaders == null)
105+
{
106+
throw new InvalidOperationException("extraHeaders is null");
107+
}
108+
109+
_htmlConversionBehaviors.ExtraHeaders = extraHeaders;
110+
111+
return this;
112+
}
113+
114+
/// <summary>
115+
/// Adds a cookie to store in the Chromium cookie jar.
116+
/// </summary>
117+
/// <param name="cookie">The cookie to add</param>
118+
/// <returns></returns>
119+
/// <exception cref="ArgumentNullException"></exception>
120+
public HtmlConversionBehaviorBuilder AddCookie(Cookie cookie)
121+
{
122+
if (cookie == null)
123+
{
124+
throw new ArgumentNullException(nameof(cookie));
125+
}
126+
127+
_htmlConversionBehaviors.Cookies ??= new List<Cookie>();
128+
129+
Cookie.Validate(cookie);
130+
131+
_htmlConversionBehaviors.Cookies.Add(cookie);
132+
133+
return this;
134+
}
135+
136+
/// <summary>
137+
/// Sets the document metadata.
138+
/// Not all metadata are writable. Consider taking a look at https://exiftool.org/TagNames/XMP.html#pdf for an
139+
/// (exhaustive?) list of available metadata.
140+
/// </summary>
141+
/// <param name="dictionary"></param>
142+
/// <returns></returns>
143+
public HtmlConversionBehaviorBuilder SetMetadata(IDictionary<string, object> dictionary)
144+
{
145+
SetMetadata(JObject.FromObject(dictionary));
146+
147+
return this;
148+
}
149+
150+
/// <summary>
151+
/// Sets the document metadata.
152+
/// Not all metadata are writable. Consider taking a look at https://exiftool.org/TagNames/XMP.html#pdf for an
153+
/// (exhaustive?) list of available metadata.
154+
/// </summary>
155+
/// <param name="metadata"></param>
156+
/// <returns></returns>
157+
public HtmlConversionBehaviorBuilder SetMetadata(JObject metadata)
158+
{
159+
if (metadata == null)
160+
{
161+
throw new InvalidOperationException("metadata is null");
162+
}
163+
164+
_htmlConversionBehaviors.MetaData = metadata;
165+
166+
return this;
167+
}
168+
169+
/// <summary>
170+
/// Tells gotenberg to return a 409 response if there are exceptions in the Chromium console.
171+
/// </summary>
172+
/// <returns></returns>
173+
public HtmlConversionBehaviorBuilder FailOnConsoleExceptions()
174+
{
175+
_htmlConversionBehaviors.FailOnConsoleExceptions = true;
176+
177+
return this;
178+
}
179+
180+
/// <summary>
181+
/// Configures gotenberg to emulate html loading as screen. By default, it loads it as print
182+
/// </summary>
183+
/// <returns></returns>
184+
public HtmlConversionBehaviorBuilder EmulateAsScreen()
185+
{
186+
_htmlConversionBehaviors.EmulatedMediaType = "screen";
187+
188+
return this;
189+
}
190+
191+
/// <summary>
192+
/// Gotenberg 8+ ONLY: Configures gotenberg to not wait for Chromium network to be idle.
193+
/// </summary>
194+
/// <returns></returns>
195+
public HtmlConversionBehaviorBuilder SkipNetworkIdleEvent()
196+
{
197+
_htmlConversionBehaviors.SkipNetworkIdleEvent = true;
198+
199+
return this;
200+
}
201+
202+
/// <summary>
203+
/// Sets the format of the resulting PDF document
204+
/// </summary>
205+
/// <param name="format"></param>
206+
/// <returns></returns>
207+
/// <exception cref="InvalidOperationException"></exception>
208+
public HtmlConversionBehaviorBuilder SetPdfFormat(ConversionPdfFormats format)
209+
{
210+
if (format == default)
211+
{
212+
throw new InvalidOperationException("Invalid PDF format specified");
213+
}
214+
215+
_htmlConversionBehaviors.PdfFormat = format;
216+
217+
return this;
218+
}
219+
220+
/// <summary>
221+
/// This tells gotenberg to enable Universal Access for the resulting PDF.
222+
/// </summary>
223+
public HtmlConversionBehaviorBuilder SetPdfUa(bool enablePdfUa = true)
224+
{
225+
_htmlConversionBehaviors.EnablePdfUa = enablePdfUa;
226+
227+
return this;
228+
}
229+
}

0 commit comments

Comments
 (0)