From 9d9d663a790a19b16ec7d486156be7a95afd0e92 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 27 Oct 2025 12:54:24 +0800 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=E6=B6=88=E9=99=A4=E8=AD=A6?= =?UTF-8?q?=E5=91=8A=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/DefaultPdfService.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/BootstrapBlazor.Html2Pdf/Services/DefaultPdfService.cs b/src/components/BootstrapBlazor.Html2Pdf/Services/DefaultPdfService.cs index 935e3bbc..d9588cd5 100644 --- a/src/components/BootstrapBlazor.Html2Pdf/Services/DefaultPdfService.cs +++ b/src/components/BootstrapBlazor.Html2Pdf/Services/DefaultPdfService.cs @@ -161,13 +161,16 @@ private async Task LaunchBrowserAsync() private void Log(Exception? exception, string? message, params object?[] args) { - if (args.Length != 0) + if (logger.IsEnabled(LogLevel.Information)) { - logger.LogInformation(exception, "{Message} | Args: {Args}", message, args); - } - else - { - logger.LogInformation(exception, "{Message}", message); + if (args.Length != 0) + { + logger.LogInformation(exception, "{Message} | Args: {Args}", message, args); + } + else + { + logger.LogInformation(exception, "{Message}", message); + } } } } From 1eedacd5c02d6e23008dbfe693e9e2a84c581828 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 27 Oct 2025 12:54:46 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20PdfOptions=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/DefaultPdfService.cs | 44 +++++++------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/components/BootstrapBlazor.Html2Pdf/Services/DefaultPdfService.cs b/src/components/BootstrapBlazor.Html2Pdf/Services/DefaultPdfService.cs index d9588cd5..cf60fc51 100644 --- a/src/components/BootstrapBlazor.Html2Pdf/Services/DefaultPdfService.cs +++ b/src/components/BootstrapBlazor.Html2Pdf/Services/DefaultPdfService.cs @@ -1,4 +1,4 @@ -// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Website: https://www.blazor.zone or https://argozhang.github.io/ @@ -19,10 +19,7 @@ class DefaultPdfService(ILogger logger) : IHtml2Pdf /// public IWebProxy? WebProxy { get; set; } - /// - /// - /// - public async Task PdfDataAsync(string url) + public async Task PdfDataAsync(string url, PdfOptions? options = null) { try { @@ -30,7 +27,7 @@ public async Task PdfDataAsync(string url) await using var page = await browser.NewPageAsync(); await page.GoToAsync(url); - return await page.PdfDataAsync(); + return await page.PdfDataAsync(GetOptions(options)); } catch (Exception ex) { @@ -39,10 +36,7 @@ public async Task PdfDataAsync(string url) } } - /// - /// - /// - public async Task PdfStreamAsync(string url) + public async Task PdfStreamAsync(string url, PdfOptions? options = null) { try { @@ -50,7 +44,7 @@ public async Task PdfStreamAsync(string url) await using var page = await browser.NewPageAsync(); await page.GoToAsync(url); - return await page.PdfStreamAsync(); + return await page.PdfStreamAsync(GetOptions(options)); } catch (Exception ex) { @@ -59,13 +53,7 @@ public async Task PdfStreamAsync(string url) } } - /// - /// Export method - /// - /// html raw string - /// - /// - public async Task PdfDataFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null) + public async Task PdfDataFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null, PdfOptions? options = null) { try { @@ -76,7 +64,7 @@ public async Task PdfDataFromHtmlAsync(string html, IEnumerable? await AddStyleTagAsync(page, links); await AddScriptTagAsync(page, scripts); - return await page.PdfDataAsync(); + return await page.PdfDataAsync(GetOptions(options)); } catch (Exception ex) { @@ -85,13 +73,7 @@ public async Task PdfDataFromHtmlAsync(string html, IEnumerable? } } - /// - /// Export method - /// - /// html raw string - /// - /// - public async Task PdfStreamFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null) + public async Task PdfStreamFromHtmlAsync(string html, IEnumerable? links = null, IEnumerable? scripts = null, PdfOptions? options = null) { try { @@ -102,7 +84,7 @@ public async Task PdfStreamFromHtmlAsync(string html, IEnumerable PdfStreamFromHtmlAsync(string html, IEnumerable? links = null) { var styles = new List(); From e6e196cd43cf8923d3225778e4c8af45b08114d8 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 27 Oct 2025 12:55:00 +0800 Subject: [PATCH 3/3] chore: bump version 9.0.6-beta01 --- .../BootstrapBlazor.Html2Pdf/BootstrapBlazor.Html2Pdf.csproj | 4 ++-- .../Extensions/ServiceCollectionExtensions.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/BootstrapBlazor.Html2Pdf/BootstrapBlazor.Html2Pdf.csproj b/src/components/BootstrapBlazor.Html2Pdf/BootstrapBlazor.Html2Pdf.csproj index 29e7dc3d..bca9d00b 100644 --- a/src/components/BootstrapBlazor.Html2Pdf/BootstrapBlazor.Html2Pdf.csproj +++ b/src/components/BootstrapBlazor.Html2Pdf/BootstrapBlazor.Html2Pdf.csproj @@ -1,7 +1,7 @@  - 9.0.4 + 9.0.6-beta01 @@ -10,7 +10,7 @@ - + diff --git a/src/components/BootstrapBlazor.Html2Pdf/Extensions/ServiceCollectionExtensions.cs b/src/components/BootstrapBlazor.Html2Pdf/Extensions/ServiceCollectionExtensions.cs index 8d2b2169..daccd909 100644 --- a/src/components/BootstrapBlazor.Html2Pdf/Extensions/ServiceCollectionExtensions.cs +++ b/src/components/BootstrapBlazor.Html2Pdf/Extensions/ServiceCollectionExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Website: https://www.blazor.zone or https://argozhang.github.io/