From 57e4a885f6325d9783f8b3e124e32dddceafc035 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 27 Oct 2025 12:42:17 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20PdfOptions=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Options/PdfOptions.cs | 17 ++++++++++++ .../Services/DefaultHtml2PdfService.cs | 26 +++---------------- src/BootstrapBlazor/Services/IHtml2Pdf.cs | 12 ++++++--- 3 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 src/BootstrapBlazor/Options/PdfOptions.cs 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); } From 9597ad4bf0e8899298fb4fa572ddf36834b37066 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 27 Oct 2025 12:44:29 +0800 Subject: [PATCH 2/4] chore: bump version 9.11.5-beta07 --- src/BootstrapBlazor/BootstrapBlazor.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From e0f781baea181fa0ecef25bf3f1a8b151dbcc6b1 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 27 Oct 2025 12:48:43 +0800 Subject: [PATCH 3/4] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/ExportPdfButtonTest.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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"))); } } From 7688b29cd2dee000cef1f2eb8e5bbec118ccbef6 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 27 Oct 2025 12:58:43 +0800 Subject: [PATCH 4/4] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Services/Html2PdfServiceTest.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) 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); + } }