diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index b6a4c1a7478..58bb76a12db 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,11 +1,11 @@  - 9.11.5-beta06 + 9.11.5-beta07 - 10.0.0-rc.2.1.5 + 10.0.0-rc.2.1.6 diff --git a/src/BootstrapBlazor/Options/PdfOptions.cs b/src/BootstrapBlazor/Options/PdfOptions.cs new file mode 100644 index 00000000000..23e744268bd --- /dev/null +++ b/src/BootstrapBlazor/Options/PdfOptions.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License +// See the LICENSE file in the project root for more information. +// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone + +namespace BootstrapBlazor.Components; + +/// +/// PdfOptions 实例用于设置导出 Pdf 相关选项 +/// +public class PdfOptions +{ + /// + /// 获得/设置 是否横向打印 默认 false + /// + public bool Landscape { get; set; } +} diff --git a/src/BootstrapBlazor/Services/DefaultHtml2PdfService.cs b/src/BootstrapBlazor/Services/DefaultHtml2PdfService.cs index aee8de4afe5..778e0ef9279 100644 --- a/src/BootstrapBlazor/Services/DefaultHtml2PdfService.cs +++ b/src/BootstrapBlazor/Services/DefaultHtml2PdfService.cs @@ -12,29 +12,11 @@ class DefaultHtml2PdfService : IHtml2Pdf { private const string ErrorMessage = "请增加依赖包 BootstrapBlazor.Html2Pdf 通过 AddBootstrapBlazorHtml2PdfService 进行服务注入; Please add BootstrapBlazor.Html2Pdf package and use AddBootstrapBlazorHtml2PdfService inject service"; - /// - /// - /// - public Task PdfDataAsync(string url) => throw new NotImplementedException(ErrorMessage); + public Task PdfDataAsync(string url, PdfOptions? options = null) => throw new NotImplementedException(ErrorMessage); - /// - /// - /// - public Task PdfStreamAsync(string url) => throw new NotImplementedException(ErrorMessage); + public Task PdfStreamAsync(string url, PdfOptions? options = null) => throw new NotImplementedException(ErrorMessage); - /// - /// Export method - /// - /// html raw string - /// - /// - public Task PdfDataFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null) => throw new NotImplementedException(ErrorMessage); + public Task PdfDataFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null, PdfOptions? options = null) => throw new NotImplementedException(ErrorMessage); - /// - /// Export method - /// - /// html raw string - /// - /// - public Task PdfStreamFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null) => throw new NotImplementedException(ErrorMessage); + public Task PdfStreamFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null, PdfOptions? options = null) => throw new NotImplementedException(ErrorMessage); } diff --git a/src/BootstrapBlazor/Services/IHtml2Pdf.cs b/src/BootstrapBlazor/Services/IHtml2Pdf.cs index 3be30f033af..501841c8b07 100644 --- a/src/BootstrapBlazor/Services/IHtml2Pdf.cs +++ b/src/BootstrapBlazor/Services/IHtml2Pdf.cs @@ -22,13 +22,15 @@ public interface IHtml2Pdf /// Export method /// /// url - Task PdfDataAsync(string url); + /// + Task PdfDataAsync(string url, PdfOptions? options = null); /// /// Export method /// /// url - Task PdfStreamAsync(string url); + /// + Task PdfStreamAsync(string url, PdfOptions? options = null); /// /// Export method @@ -36,7 +38,8 @@ public interface IHtml2Pdf /// html raw string /// /// - Task PdfDataFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null); + /// + Task PdfDataFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null, PdfOptions? options = null); /// /// Export method @@ -44,5 +47,6 @@ public interface IHtml2Pdf /// html raw string /// /// - Task PdfStreamFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null); + /// + Task PdfStreamFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null, PdfOptions? options = null); } diff --git a/test/UnitTest/Components/ExportPdfButtonTest.cs b/test/UnitTest/Components/ExportPdfButtonTest.cs index 0496503bc28..3d4a1205099 100644 --- a/test/UnitTest/Components/ExportPdfButtonTest.cs +++ b/test/UnitTest/Components/ExportPdfButtonTest.cs @@ -157,21 +157,21 @@ public void ExportPdfButtonSettings_Ok() class MockHtml2PdfService : IHtml2Pdf { - public Task PdfDataAsync(string url) + public Task PdfDataAsync(string url, PdfOptions? options = null) { throw new NotImplementedException(); } - public Task PdfDataFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null) + public Task PdfDataFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null, PdfOptions? options = null) { throw new NotImplementedException(); } - public Task PdfStreamAsync(string url) + public Task PdfStreamAsync(string url, PdfOptions? options = null) { throw new NotImplementedException(); } - public Task PdfStreamFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null) => Task.FromResult(new MemoryStream(Encoding.UTF8.GetBytes("Hello World"))); + public Task PdfStreamFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null, PdfOptions? options = null) => Task.FromResult(new MemoryStream(Encoding.UTF8.GetBytes("Hello World"))); } } diff --git a/test/UnitTest/Services/Html2PdfServiceTest.cs b/test/UnitTest/Services/Html2PdfServiceTest.cs index e23de3caf1d..d5cd9502edc 100644 --- a/test/UnitTest/Services/Html2PdfServiceTest.cs +++ b/test/UnitTest/Services/Html2PdfServiceTest.cs @@ -21,4 +21,14 @@ public async Task ExportPdf_Error() await Assert.ThrowsAsync(() => pdfService.PdfDataFromHtmlAsync("

Test

")); await Assert.ThrowsAsync(() => pdfService.PdfStreamFromHtmlAsync("

Test

")); } + + [Fact] + public void PdfOptions_Ok() + { + var options = new PdfOptions + { + Landscape = true + }; + Assert.True(options.Landscape); + } }