Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for the fontSize isse #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion source/Append.Blazor.Printing/PrintOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
/// <summary>
/// Document source: pdf url or base64.
Expand All @@ -41,5 +42,10 @@ public PrintOptions(string printable, string modalMessage, PrintType printType =
/// Used when printing PDF documents passed as base64 data.
/// </summary>
public bool Base64 { get; set; }

/// <summary>
/// Uses empty font_size parameter as a workaround for issue https://github.com/crabbly/Print.js/issues/534.
/// </summary>
public bool UseFontSizeWorkaround { get; set; }
}
}
5 changes: 5 additions & 0 deletions source/Append.Blazor.Printing/PrintOptionsAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Text.Json.Serialization;

namespace Append.Blazor.Printing
{
Expand All @@ -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)
{
Expand All @@ -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
}
}
}