Skip to content

Commit

Permalink
Completes #50
Browse files Browse the repository at this point in the history
added support for Metadata.
  • Loading branch information
Jaben committed Feb 12, 2025
1 parent f324dd2 commit e900c1e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
29 changes: 29 additions & 0 deletions lib/Domain/Builders/Faceted/HtmlConversionBehaviorBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,35 @@ public HtmlConversionBehaviorBuilder AddAdditionalHeaders(JObject extraHeaders)
return this;
}

/// <summary>
/// Sets the document metadata.
/// Not all metadata are writable. Consider taking a look at https://exiftool.org/TagNames/XMP.html#pdf for an (exhaustive?) list of available metadata.
/// </summary>
/// <param name="dictionary"></param>
/// <returns></returns>
public HtmlConversionBehaviorBuilder SetMetadata(IDictionary<string, object> dictionary)
{
SetMetadata(new JObject(dictionary));

return this;
}

/// <summary>
/// Sets the document metadata.
/// Not all metadata are writable. Consider taking a look at https://exiftool.org/TagNames/XMP.html#pdf for an (exhaustive?) list of available metadata.
/// </summary>
/// <param name="metadata"></param>
/// <returns></returns>

public HtmlConversionBehaviorBuilder SetMetadata(JObject metadata)
{
if (metadata == null) throw new InvalidOperationException("metadata is null");

this._htmlConversionBehaviors.MetaData = metadata;

return this;
}

/// <summary>
/// Tells gotenberg to return a 409 response if there are exceptions in the Chromium console.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion lib/Domain/Requests/Facets/ExtraHttpHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void Add(string name, string value)
{
if (name.IsNotSet()) throw new ArgumentException("Header name is null or empty");

this._headers.Add(name, new[] { value });
this._headers.Add(name, [value]);
}

public void Add(string name, IEnumerable<string> values)
Expand Down
8 changes: 8 additions & 0 deletions lib/Domain/Requests/Facets/HtmlConversionBehaviors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public class HtmlConversionBehaviors : IConvertToHttpContent
[MultiFormHeader(Constants.Gotenberg.Chromium.Shared.HtmlConvert.ExtraHttpHeaders)]
public JObject? ExtraHeaders { get; set; }

/// <summary>
/// The metadata to write to the PDF (JSON format).
/// Not all metadata are writable.
/// Consider taking a look at https://exiftool.org/TagNames/XMP.html#pdf for an (exhaustive?) list of available metadata.
/// </summary>
[MultiFormHeader(Constants.Gotenberg.Chromium.Shared.HtmlConvert.MetaData)]
public JObject? MetaData { get; set; }

/// <summary>
/// Tells gotenberg to return a 409 response if there are exceptions in the Chromium console.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion lib/Domain/Requests/Facets/Webhook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public bool IsConfigured()

public IEnumerable<(string, string?)> GetHeaders()
{
if (!this.IsConfigured()) return Enumerable.Empty<(string, string?)>();
if (!this.IsConfigured()) return [];

var webHookHeaders = new List<(string Name, string? Value)>
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Infrastructure/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ public static class HtmlConvert

public const string ExtraHttpHeaders = "extraHttpHeaders";

public const string MetaData = "metadata";

//javascript
public const string FailOnConsoleExceptions = "failOnConsoleExceptions";

Expand Down

0 comments on commit e900c1e

Please sign in to comment.