Skip to content

Commit

Permalink
Merge branch 'release/2.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaben committed Feb 7, 2025
2 parents 45bcdac + 6813c91 commit dd202b5
Show file tree
Hide file tree
Showing 22 changed files with 529 additions and 358 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public void ConfigureServices(IServiceCollection services)
var builder = new HtmlRequestBuilder()
.AddDocument(doc =>
doc.SetBody(GetBody()).SetFooter(GetFooter())
).WithDimensions(dims =>
).WithPageProperties(pp =>
{
dims.SetPaperSize(PaperSizes.A3)
pp.SetPaperSize(PaperSizes.A3)
.SetMargins(Margins.None)
.SetScale(.99);
}).WithAsyncAssets(async assets => assets.AddItem("some-image.jpg", await GetImageBytes()));
Expand Down Expand Up @@ -95,12 +95,12 @@ public async Task<Stream> CreateFromUrl(string headerPath, string footerPath)
.AddAsyncHeaderFooter(async
doc => doc.SetHeader(await File.ReadAllTextAsync(headerPath))
.SetFooter(await File.ReadAllBytesAsync(footerPath)
)).WithDimensions(dims =>
)).WithPageProperties(pp =>
{
dims.SetPaperSize(PaperSizes.A4)
pp.SetPaperSize(PaperSizes.A4)
.SetMargins(Margins.None)
.SetScale(.90)
.LandScape();
.SetLandscape();
});

var request = await builder.BuildAsync();
Expand Down Expand Up @@ -130,14 +130,14 @@ public async Task<Stream> CreateFromMarkdown()
.AddAsyncDocument(async
doc => doc.SetHeader(await this.GetHeaderAsync())
.SetBody(await GetBodyAsync())
.ContainsMarkdown()
.SetContainsMarkdown()
.SetFooter(await GetFooterAsync())
).WithDimensions(dims =>
).WithPageProperties(pp =>
{
dims.UseChromeDefaults().LandScape().SetScale(.90);
pp.UseChromeDefaults().SetLandscape().SetScale(.90);
}).WithAsyncAssets(async
a => a.AddItems(await GetMarkdownAssets())
));
);

var request = await builder.BuildAsync();
return await _sharpClient.HtmlToPdfAsync(request);
Expand Down Expand Up @@ -169,7 +169,7 @@ public async Task<Stream> CreateFromMarkdown()
dimBuilder.SetPaperSize(PaperSizes.A4)
.SetMargins(Margins.None)
.SetScale(.90)
.LandScape();
.SetLandscape();
});

var request = await builder.BuildAsync();
Expand Down Expand Up @@ -217,9 +217,9 @@ IEnumerable<UrlRequestBuilder> CreateBuilders(IEnumerable<Uri> uris)
{
dimBuilder.UseChromeDefaults()
.SetScale(.90)
.LandScape()
.MarginLeft(.5)
.MarginRight(.5);
.SetLandscape()
.SetMarginLeft(.5)
.SetMarginRight(.5);
});
}

Expand Down
32 changes: 27 additions & 5 deletions lib/Domain/Builders/BaseChromiumBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,44 @@ public abstract class BaseChromiumBuilder<TRequest, TBuilder>(TRequest request)
where TRequest : ChromeRequest
where TBuilder : BaseChromiumBuilder<TRequest, TBuilder>
{
public TBuilder WithDimensions(Action<DimensionBuilder> action)
[Obsolete("Use WithPageProperties")]
public TBuilder WithDimensions(Action<PagePropertyBuilder> action)
{
if (action == null) throw new ArgumentNullException(nameof(action));

var builder = new DimensionBuilder(this.Request.Dimensions);
var builder = new PagePropertyBuilder(this.Request.PageProperties);

action(builder);

this.Request.Dimensions = builder.GetDimensions();
this.Request.PageProperties = builder.GetPageProperties();

return (TBuilder)this;
}

public TBuilder WithDimensions(Dimensions dimensions)
[Obsolete("Use WithPageProperties")]
public TBuilder WithDimensions(PageProperties pageProperties)
{
this.Request.Dimensions = dimensions ?? throw new ArgumentNullException(nameof(dimensions));
this.Request.PageProperties = pageProperties ?? throw new ArgumentNullException(nameof(pageProperties));
return (TBuilder)this;
}

public TBuilder WithPageProperties(Action<PagePropertyBuilder> action)
{
if (action == null) throw new ArgumentNullException(nameof(action));

var builder = new PagePropertyBuilder(this.Request.PageProperties);

action(builder);

this.Request.PageProperties = builder.GetPageProperties();

return (TBuilder)this;
}

public TBuilder WithPageProperties(PageProperties pageProperties)
{
this.Request.PageProperties = pageProperties ?? throw new ArgumentNullException(nameof(pageProperties));

return (TBuilder)this;
}

Expand Down
147 changes: 0 additions & 147 deletions lib/Domain/Builders/Faceted/DimensionBuilder.cs

This file was deleted.

24 changes: 8 additions & 16 deletions lib/Domain/Builders/Faceted/DocumentBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019-2024 Chris Mohan, Jaben Cargman
// Copyright 2019-2025 Chris Mohan, Jaben Cargman
// and GotenbergSharpApiClient Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,8 +13,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.



namespace Gotenberg.Sharp.API.Client.Domain.Builders.Faceted;

/// <summary>
Expand All @@ -36,33 +34,35 @@ public DocumentBuilder(FullDocument content, Action<bool> setContainsMarkdown)

#region body


[Obsolete("Use SetContainsMarkdown()")]
public DocumentBuilder ContainsMarkdown(bool containsMarkdown = true)
{
this._setContainsMarkdown(containsMarkdown);
return this;
}


public DocumentBuilder SetContainsMarkdown(bool containsMarkdown = true)
{
this._setContainsMarkdown(containsMarkdown);
return this;
}

public DocumentBuilder SetBody(ContentItem body)
{
this._content.Body = body ?? throw new ArgumentNullException(nameof(body));
return this;
}


public DocumentBuilder SetBody(string body)
{
return this.SetBody(new ContentItem(body));
}


public DocumentBuilder SetBody(byte[] body)
{
return this.SetBody(new ContentItem(body));
}


public DocumentBuilder SetBody(Stream body)
{
return this.SetBody(new ContentItem(body));
Expand All @@ -72,26 +72,22 @@ public DocumentBuilder SetBody(Stream body)

#region header


public DocumentBuilder SetHeader(ContentItem header)
{
this._content.Header = header ?? throw new ArgumentNullException(nameof(header));
return this;
}


public DocumentBuilder SetHeader(string header)
{
return this.SetHeader(new ContentItem(header));
}


public DocumentBuilder SetHeader(byte[] header)
{
return this.SetHeader(new ContentItem(header));
}


public DocumentBuilder SetHeader(Stream header)
{
return this.SetHeader(new ContentItem(header));
Expand All @@ -101,26 +97,22 @@ public DocumentBuilder SetHeader(Stream header)

#region footer


public DocumentBuilder SetFooter(ContentItem footer)
{
this._content.Footer = footer ?? throw new ArgumentNullException(nameof(footer));
return this;
}


public DocumentBuilder SetFooter(string footer)
{
return this.SetFooter(new ContentItem(footer));
}


public DocumentBuilder SetFooter(byte[] footer)
{
return this.SetFooter(new ContentItem(footer));
}


public DocumentBuilder SetFooter(Stream footer)
{
return this.SetFooter(new ContentItem(footer));
Expand Down
Loading

0 comments on commit dd202b5

Please sign in to comment.