From 55717e8b66730e041521495ecd226de14a6a7d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Josai?= Date: Wed, 1 Feb 2023 13:04:44 +0100 Subject: [PATCH 1/2] Added font_size workaround --- .../wwwroot/examples/Example.md | 2 -- source/Append.Blazor.Printing/PrintOptions.cs | 8 +++++++- source/Append.Blazor.Printing/PrintOptionsAdapter.cs | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/samples/Append.Blazor.Printing.Wasm/wwwroot/examples/Example.md b/samples/Append.Blazor.Printing.Wasm/wwwroot/examples/Example.md index 9630655..bf608c3 100644 --- a/samples/Append.Blazor.Printing.Wasm/wwwroot/examples/Example.md +++ b/samples/Append.Blazor.Printing.Wasm/wwwroot/examples/Example.md @@ -12,8 +12,6 @@ [Parameter] public RenderFragment Documentation { get; set; } [Parameter] public RenderFragment Code { get; set; } [Parameter] public string Name { get; set; } - private string id => Guid.NewGuid().ToString(); - private string sampleCode; protected override async Task OnParametersSetAsync() diff --git a/source/Append.Blazor.Printing/PrintOptions.cs b/source/Append.Blazor.Printing/PrintOptions.cs index d8ab0b8..98b64a7 100644 --- a/source/Append.Blazor.Printing/PrintOptions.cs +++ b/source/Append.Blazor.Printing/PrintOptions.cs @@ -14,12 +14,13 @@ public PrintOptions(string printable) Printable = printable; } - public PrintOptions(string printable, string modalMessage, PrintType printType = PrintType.Pdf) + public PrintOptions(string printable, string modalMessage, PrintType printType = PrintType.Pdf, bool useFontSizeWorkaround = false) { Printable = printable; ModalMessage = modalMessage; ShowModal = true; Type = printType; + UseFontSizeWorkaround = useFontSizeWorkaround; } /// /// Document source: pdf url or base64. @@ -41,5 +42,10 @@ public PrintOptions(string printable, string modalMessage, PrintType printType = /// Used when printing PDF documents passed as base64 data. /// public bool Base64 { get; set; } + + /// + /// Uses empty font_size parameter as a workaround for issue https://github.com/crabbly/Print.js/issues/534. + /// + public bool UseFontSizeWorkaround { get; set; } } } diff --git a/source/Append.Blazor.Printing/PrintOptionsAdapter.cs b/source/Append.Blazor.Printing/PrintOptionsAdapter.cs index ea31d79..dbdcf4d 100644 --- a/source/Append.Blazor.Printing/PrintOptionsAdapter.cs +++ b/source/Append.Blazor.Printing/PrintOptionsAdapter.cs @@ -1,4 +1,5 @@ using System; +using System.Text.Json.Serialization; namespace Append.Blazor.Printing { @@ -13,6 +14,9 @@ internal record PrintOptionsAdapter public string ModalMessage { get; init; } = "Retrieving Document..."; public bool? Base64 { get; set; } public string TargetStyles { get; set; } = "['*']"; + [JsonPropertyName("font_size")] + //HACK: This is a hack to get around the fact that the PrintJS is dead and issue https://github.com/crabbly/Print.js/issues/534 is not getting fixed anytime soon. + public string FontSize { get; set; } public PrintOptionsAdapter(PrintOptions options) { @@ -21,6 +25,7 @@ public PrintOptionsAdapter(PrintOptions options) ShowModal = options.ShowModal; ModalMessage = options.ModalMessage; Base64 = options.Base64 == true ? true : null; + FontSize = options.UseFontSizeWorkaround ? "" : "12px"; //12px is the default value in PrintJS } } } From 6f6a61c5d18626103b0b645ca66a00109358d471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Josai?= Date: Fri, 3 Feb 2023 13:17:53 +0100 Subject: [PATCH 2/2] Did not mean to tough this --- samples/Append.Blazor.Printing.Wasm/wwwroot/examples/Example.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/Append.Blazor.Printing.Wasm/wwwroot/examples/Example.md b/samples/Append.Blazor.Printing.Wasm/wwwroot/examples/Example.md index bf608c3..9630655 100644 --- a/samples/Append.Blazor.Printing.Wasm/wwwroot/examples/Example.md +++ b/samples/Append.Blazor.Printing.Wasm/wwwroot/examples/Example.md @@ -12,6 +12,8 @@ [Parameter] public RenderFragment Documentation { get; set; } [Parameter] public RenderFragment Code { get; set; } [Parameter] public string Name { get; set; } + private string id => Guid.NewGuid().ToString(); + private string sampleCode; protected override async Task OnParametersSetAsync()