Skip to content

Commit e900c1e

Browse files
committed
Completes #50
added support for Metadata.
1 parent f324dd2 commit e900c1e

5 files changed

Lines changed: 41 additions & 2 deletions

File tree

lib/Domain/Builders/Faceted/HtmlConversionBehaviorBuilder.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,35 @@ public HtmlConversionBehaviorBuilder AddAdditionalHeaders(JObject extraHeaders)
102102
return this;
103103
}
104104

105+
/// <summary>
106+
/// Sets the document metadata.
107+
/// Not all metadata are writable. Consider taking a look at https://exiftool.org/TagNames/XMP.html#pdf for an (exhaustive?) list of available metadata.
108+
/// </summary>
109+
/// <param name="dictionary"></param>
110+
/// <returns></returns>
111+
public HtmlConversionBehaviorBuilder SetMetadata(IDictionary<string, object> dictionary)
112+
{
113+
SetMetadata(new JObject(dictionary));
114+
115+
return this;
116+
}
117+
118+
/// <summary>
119+
/// Sets the document metadata.
120+
/// Not all metadata are writable. Consider taking a look at https://exiftool.org/TagNames/XMP.html#pdf for an (exhaustive?) list of available metadata.
121+
/// </summary>
122+
/// <param name="metadata"></param>
123+
/// <returns></returns>
124+
125+
public HtmlConversionBehaviorBuilder SetMetadata(JObject metadata)
126+
{
127+
if (metadata == null) throw new InvalidOperationException("metadata is null");
128+
129+
this._htmlConversionBehaviors.MetaData = metadata;
130+
131+
return this;
132+
}
133+
105134
/// <summary>
106135
/// Tells gotenberg to return a 409 response if there are exceptions in the Chromium console.
107136
/// </summary>

lib/Domain/Requests/Facets/ExtraHttpHeaders.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void Add(string name, string value)
2323
{
2424
if (name.IsNotSet()) throw new ArgumentException("Header name is null or empty");
2525

26-
this._headers.Add(name, new[] { value });
26+
this._headers.Add(name, [value]);
2727
}
2828

2929
public void Add(string name, IEnumerable<string> values)

lib/Domain/Requests/Facets/HtmlConversionBehaviors.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ public class HtmlConversionBehaviors : IConvertToHttpContent
5656
[MultiFormHeader(Constants.Gotenberg.Chromium.Shared.HtmlConvert.ExtraHttpHeaders)]
5757
public JObject? ExtraHeaders { get; set; }
5858

59+
/// <summary>
60+
/// The metadata to write to the PDF (JSON format).
61+
/// Not all metadata are writable.
62+
/// Consider taking a look at https://exiftool.org/TagNames/XMP.html#pdf for an (exhaustive?) list of available metadata.
63+
/// </summary>
64+
[MultiFormHeader(Constants.Gotenberg.Chromium.Shared.HtmlConvert.MetaData)]
65+
public JObject? MetaData { get; set; }
66+
5967
/// <summary>
6068
/// Tells gotenberg to return a 409 response if there are exceptions in the Chromium console.
6169
/// </summary>

lib/Domain/Requests/Facets/Webhook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public bool IsConfigured()
9393

9494
public IEnumerable<(string, string?)> GetHeaders()
9595
{
96-
if (!this.IsConfigured()) return Enumerable.Empty<(string, string?)>();
96+
if (!this.IsConfigured()) return [];
9797

9898
var webHookHeaders = new List<(string Name, string? Value)>
9999
{

lib/Infrastructure/Constants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ public static class HtmlConvert
264264

265265
public const string ExtraHttpHeaders = "extraHttpHeaders";
266266

267+
public const string MetaData = "metadata";
268+
267269
//javascript
268270
public const string FailOnConsoleExceptions = "failOnConsoleExceptions";
269271

0 commit comments

Comments
 (0)