diff --git a/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj b/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj
index 26642cca3e4..70e23b9d454 100644
--- a/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj
+++ b/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj
@@ -44,7 +44,7 @@
-
+
diff --git a/src/BootstrapBlazor.Server/Components/Samples/Html2Pdfs.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Html2Pdfs.razor.cs
index 904fb3bef6e..1fe385f9465 100644
--- a/src/BootstrapBlazor.Server/Components/Samples/Html2Pdfs.razor.cs
+++ b/src/BootstrapBlazor.Server/Components/Samples/Html2Pdfs.razor.cs
@@ -86,7 +86,10 @@ private async Task OnExportAsync()
""";
// 增加网页所需样式表文件
- using var stream = await Html2PdfService.PdfStreamFromHtmlAsync(htmlString, [$"{NavigationManager.BaseUri}_content/BootstrapBlazor/css/bootstrap.blazor.bundle.min.css"]);
+ using var stream = await Html2PdfService.PdfStreamFromHtmlAsync(htmlString, [$"{NavigationManager.BaseUri}_content/BootstrapBlazor/css/bootstrap.blazor.bundle.min.css"], options: new PdfOptions()
+ {
+ Format = PaperFormat.A4
+ });
// 下载 Pdf 文件
await DownloadService.DownloadFromStreamAsync($"table-{DateTime.Now:HHmmss}.pdf", stream);
diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj
index b92aeced2c8..69c1e0ba2b1 100644
--- a/src/BootstrapBlazor/BootstrapBlazor.csproj
+++ b/src/BootstrapBlazor/BootstrapBlazor.csproj
@@ -1,11 +1,11 @@
- 9.11.5-beta10
+ 9.11.5-beta11
- 10.0.0-rc.2.1.9
+ 10.0.0-rc.2.1.10
diff --git a/src/BootstrapBlazor/Options/MarginOptions.cs b/src/BootstrapBlazor/Options/MarginOptions.cs
new file mode 100644
index 00000000000..4df1480c5ed
--- /dev/null
+++ b/src/BootstrapBlazor/Options/MarginOptions.cs
@@ -0,0 +1,33 @@
+// 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;
+
+///
+/// 页面边距选项
+///
+[ExcludeFromCodeCoverage]
+public record MarginOptions
+{
+ ///
+ /// Top margin, accepts values labeled with units.
+ ///
+ public object? Top { get; set; }
+
+ ///
+ /// Left margin, accepts values labeled with units.
+ ///
+ public object? Left { get; set; }
+
+ ///
+ /// Bottom margin, accepts values labeled with units.
+ ///
+ public object? Bottom { get; set; }
+
+ ///
+ /// Right margin, accepts values labeled with units.
+ ///
+ public object? Right { get; set; }
+}
diff --git a/src/BootstrapBlazor/Options/PaperFormat.cs b/src/BootstrapBlazor/Options/PaperFormat.cs
new file mode 100644
index 00000000000..21fb698dac3
--- /dev/null
+++ b/src/BootstrapBlazor/Options/PaperFormat.cs
@@ -0,0 +1,89 @@
+// 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;
+
+///
+/// 纸张规格配置类
+///
+[ExcludeFromCodeCoverage]
+public record PaperFormat
+{
+ ///
+ ///
+ ///
+ public static PaperFormat Letter => new(8.5m, 11m);
+
+ ///
+ ///
+ ///
+ public static PaperFormat Legal => new(8.5m, 14m);
+
+ ///
+ ///
+ ///
+ public static PaperFormat Tabloid => new(11m, 17m);
+
+ ///
+ ///
+ ///
+ public static PaperFormat Ledger => new(17m, 11m);
+
+ ///
+ ///
+ ///
+ public static PaperFormat A0 => new(33.1102m, 46.811m);
+
+ ///
+ ///
+ ///
+ public static PaperFormat A1 => new(23.3858m, 33.1102m);
+
+ ///
+ ///
+ ///
+ public static PaperFormat A2 => new(16.5354m, 23.3858m);
+
+ ///
+ ///
+ ///
+ public static PaperFormat A3 => new(11.6929m, 16.5354m);
+
+ ///
+ ///
+ ///
+ public static PaperFormat A4 => new(8.2677m, 11.6929m);
+
+ ///
+ ///
+ ///
+ public static PaperFormat A5 => new(5.8268m, 8.2677m);
+
+ ///
+ ///
+ ///
+ public static PaperFormat A6 => new(4.1339m, 5.8268m);
+
+ ///
+ ///
+ ///
+ public decimal Width { get; set; }
+
+ ///
+ ///
+ ///
+ public decimal Height { get; set; }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public PaperFormat(decimal width, decimal height)
+ {
+ Width = width;
+ Height = height;
+ }
+}
diff --git a/src/BootstrapBlazor/Options/PdfOptions.cs b/src/BootstrapBlazor/Options/PdfOptions.cs
index 23e744268bd..82fe4a21c0e 100644
--- a/src/BootstrapBlazor/Options/PdfOptions.cs
+++ b/src/BootstrapBlazor/Options/PdfOptions.cs
@@ -14,4 +14,29 @@ public class PdfOptions
/// 获得/设置 是否横向打印 默认 false
///
public bool Landscape { get; set; }
+
+ ///
+ /// 获得/设置 是否打印背景色 默认 false
+ ///
+ public bool PrintBackground { get; set; }
+
+ ///
+ /// 获得/设置 纸张格式 默认 A4
+ ///
+ public PaperFormat Format { get; set; } = PaperFormat.A4;
+
+ ///
+ /// 获得/设置 是否显示页眉页脚 默认 false
+ ///
+ public bool DisplayHeaderFooter { get; set; }
+
+ ///
+ /// 获得/设置 放大比例 默认 1 取值 0.1 到 2 之间
+ ///
+ public decimal Scale { get; set; } = 1;
+
+ ///
+ /// 获得/设置 页面边距 默认 none
+ ///
+ public MarginOptions MarginOptions { get; set; } = new();
}
diff --git a/test/UnitTest/Options/PdfOptionsTest.cs b/test/UnitTest/Options/PdfOptionsTest.cs
new file mode 100644
index 00000000000..e61623efffa
--- /dev/null
+++ b/test/UnitTest/Options/PdfOptionsTest.cs
@@ -0,0 +1,38 @@
+// 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 UnitTest.Options;
+
+public class PdfOptionsTest
+{
+ [Fact]
+ public void Test_PdfOptions_Ok()
+ {
+ var options = new PdfOptions()
+ {
+ Scale = 1.0m,
+ DisplayHeaderFooter = true,
+ PrintBackground = true,
+ Landscape = true,
+ Format = PaperFormat.A1,
+ MarginOptions = new MarginOptions()
+ {
+ Top = "10mm",
+ Bottom = "10mm",
+ Left = "10mm",
+ Right = "10mm"
+ }
+ };
+ Assert.Equal(1.0m, options.Scale);
+ Assert.True(options.DisplayHeaderFooter);
+ Assert.True(options.PrintBackground);
+ Assert.True(options.Landscape);
+ Assert.Equal(PaperFormat.A1, options.Format);
+ Assert.Equal("10mm", options.MarginOptions.Top);
+ Assert.Equal("10mm", options.MarginOptions.Bottom);
+ Assert.Equal("10mm", options.MarginOptions.Left);
+ Assert.Equal("10mm", options.MarginOptions.Right);
+ }
+}