Skip to content

Commit

Permalink
Added Export Form Fields support for convert endpoint. Closes #44.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaben committed Apr 17, 2024
1 parent ad7bb47 commit d93cf64
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
23 changes: 22 additions & 1 deletion lib/Domain/Builders/MergeOfficeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Gotenberg.Sharp.API.Client.Domain.Builders;
/// <summary>
/// Any non office files sent in are just ignored.
/// A nice surprise: Gotenberg/Chrome will merge in all sheets within a multi-sheet excel workbook.
/// If you send in a csv file but with an xlsx extension, it will merge it in as text.
/// If you send in a csv file but with a xlsx extension, it will merge it in as text.
/// </summary>
public sealed class MergeOfficeBuilder : BaseMergeBuilder<MergeOfficeRequest, MergeOfficeBuilder>
{
Expand All @@ -39,12 +39,33 @@ public MergeOfficeBuilder PrintAsLandscape()
return this;
}

/// <summary>
/// If provided, the API will return a pdf containing the pages in the specified range.
/// </summary>
/// <remarks>
/// The format is the same as the one from the print options of Google Chrome, e.g. 1-5,8,11-13.
/// This may move...
/// </remarks>
[PublicAPI]
public MergeOfficeBuilder SetPageRanges(string pageRanges)
{
this.Request.PageRanges = pageRanges;
return this;
}

/// <summary>
/// Set whether to export the form fields or to use the inputted/selected
/// content of the fields. Default is TRUE.
/// </summary>
/// <remarks>
/// Gotenberg v8.3+
/// </remarks>
[PublicAPI]
public MergeOfficeBuilder SetExportFormFields(bool exportFormFields)
{
this.Request.ExportFormFields = exportFormFields;
return this;
}

/// <summary>
/// This tells gotenberg to use unoconv to perform the conversion.
Expand Down
2 changes: 1 addition & 1 deletion lib/Domain/Requests/Facets/RequestConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void Validate()
/// <remarks>
/// Attention: this feature does not work if the form field webHookURL is given.
/// </remarks>
// Not sure this is useful with the way this client is used, although.. maybe Webhook requests honor it?
// Not sure if this is useful with the way this client is used, although.. maybe Webhook requests honor it?
public string? ResultFileName { get; set; }

/// <summary>
Expand Down
16 changes: 16 additions & 0 deletions lib/Domain/Requests/MergeOfficeRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,23 @@ protected override string ApiPath

public bool PrintAsLandscape { get; set; }

/// <summary>
/// If provided, the API will return a pdf containing the pages in the specified range.
/// </summary>
/// <remarks>
/// The format is the same as the one from the print options of Google Chrome, e.g. 1-5,8,11-13.
/// This may move...
/// </remarks>
public string? PageRanges { get; set; }

/// <summary>
/// Set whether to export the form fields or to use the inputted/selected
/// content of the fields. Default is TRUE.
/// </summary>
/// <remarks>
/// Gotenberg v8.3+
/// </remarks>
public bool? ExportFormFields { get; set; }

/// <summary>
/// Tells gotenberg to perform the conversion with unoconv.
Expand Down
5 changes: 5 additions & 0 deletions lib/Extensions/MergeOfficeRequestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ internal static IEnumerable<HttpContent> PropertiesToHttpContent(this MergeOffic
yield return BuildRequestBase.CreateFormDataItem(
request.PageRanges,
Constants.Gotenberg.LibreOffice.Routes.Convert.PageRanges);

if (request.ExportFormFields.HasValue)
yield return BuildRequestBase.CreateFormDataItem(
request.ExportFormFields.Value,
Constants.Gotenberg.LibreOffice.Routes.Convert.ExportFormFields);

if (!request.UseNativePdfFormat && request.Format == default) yield break;

Expand Down
2 changes: 2 additions & 0 deletions lib/Infrastructure/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public static class Convert
public const string Landscape = CrossCutting.Landscape;

public const string PageRanges = CrossCutting.PageRanges;

public const string ExportFormFields = "exportFormFields";

public const string NativePdfFormat = "nativePdfFormat";

Expand Down

0 comments on commit d93cf64

Please sign in to comment.