Skip to content

Commit 57e4a88

Browse files
committed
feat: 增加 PdfOptions 配置项
1 parent b3f199e commit 57e4a88

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
namespace BootstrapBlazor.Components;
7+
8+
/// <summary>
9+
/// PdfOptions 实例用于设置导出 Pdf 相关选项
10+
/// </summary>
11+
public class PdfOptions
12+
{
13+
/// <summary>
14+
/// 获得/设置 是否横向打印 默认 false
15+
/// </summary>
16+
public bool Landscape { get; set; }
17+
}

src/BootstrapBlazor/Services/DefaultHtml2PdfService.cs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,11 @@ class DefaultHtml2PdfService : IHtml2Pdf
1212
{
1313
private const string ErrorMessage = "请增加依赖包 BootstrapBlazor.Html2Pdf 通过 AddBootstrapBlazorHtml2PdfService 进行服务注入; Please add BootstrapBlazor.Html2Pdf package and use AddBootstrapBlazorHtml2PdfService inject service";
1414

15-
/// <summary>
16-
/// <inheritdoc/>
17-
/// </summary>
18-
public Task<byte[]> PdfDataAsync(string url) => throw new NotImplementedException(ErrorMessage);
15+
public Task<byte[]> PdfDataAsync(string url, PdfOptions? options = null) => throw new NotImplementedException(ErrorMessage);
1916

20-
/// <summary>
21-
/// <inheritdoc/>
22-
/// </summary>
23-
public Task<Stream> PdfStreamAsync(string url) => throw new NotImplementedException(ErrorMessage);
17+
public Task<Stream> PdfStreamAsync(string url, PdfOptions? options = null) => throw new NotImplementedException(ErrorMessage);
2418

25-
/// <summary>
26-
/// Export method
27-
/// </summary>
28-
/// <param name="html">html raw string</param>
29-
/// <param name="links"></param>
30-
/// <param name="scripts"></param>
31-
public Task<byte[]> PdfDataFromHtmlAsync(string html, IEnumerable<string>? links = null, IEnumerable<string>? scripts = null) => throw new NotImplementedException(ErrorMessage);
19+
public Task<byte[]> PdfDataFromHtmlAsync(string html, IEnumerable<string>? links = null, IEnumerable<string>? scripts = null, PdfOptions? options = null) => throw new NotImplementedException(ErrorMessage);
3220

33-
/// <summary>
34-
/// Export method
35-
/// </summary>
36-
/// <param name="html">html raw string</param>
37-
/// <param name="links"></param>
38-
/// <param name="scripts"></param>
39-
public Task<Stream> PdfStreamFromHtmlAsync(string html, IEnumerable<string>? links = null, IEnumerable<string>? scripts = null) => throw new NotImplementedException(ErrorMessage);
21+
public Task<Stream> PdfStreamFromHtmlAsync(string html, IEnumerable<string>? links = null, IEnumerable<string>? scripts = null, PdfOptions? options = null) => throw new NotImplementedException(ErrorMessage);
4022
}

src/BootstrapBlazor/Services/IHtml2Pdf.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,31 @@ public interface IHtml2Pdf
2222
/// Export method
2323
/// </summary>
2424
/// <param name="url">url</param>
25-
Task<byte[]> PdfDataAsync(string url);
25+
/// <param name="options"></param>
26+
Task<byte[]> PdfDataAsync(string url, PdfOptions? options = null);
2627

2728
/// <summary>
2829
/// Export method
2930
/// </summary>
3031
/// <param name="url">url</param>
31-
Task<Stream> PdfStreamAsync(string url);
32+
/// <param name="options"></param>
33+
Task<Stream> PdfStreamAsync(string url, PdfOptions? options = null);
3234

3335
/// <summary>
3436
/// Export method
3537
/// </summary>
3638
/// <param name="html">html raw string</param>
3739
/// <param name="links"></param>
3840
/// <param name="scripts"></param>
39-
Task<byte[]> PdfDataFromHtmlAsync(string html, IEnumerable<string>? links = null, IEnumerable<string>? scripts = null);
41+
/// <param name="options"></param>
42+
Task<byte[]> PdfDataFromHtmlAsync(string html, IEnumerable<string>? links = null, IEnumerable<string>? scripts = null, PdfOptions? options = null);
4043

4144
/// <summary>
4245
/// Export method
4346
/// </summary>
4447
/// <param name="html">html raw string</param>
4548
/// <param name="links"></param>
4649
/// <param name="scripts"></param>
47-
Task<Stream> PdfStreamFromHtmlAsync(string html, IEnumerable<string>? links = null, IEnumerable<string>? scripts = null);
50+
/// <param name="options"></param>
51+
Task<Stream> PdfStreamFromHtmlAsync(string html, IEnumerable<string>? links = null, IEnumerable<string>? scripts = null, PdfOptions? options = null);
4852
}

0 commit comments

Comments
 (0)