Blazor WASM proto type #261
-
Hello, I have tried the prototype code on .Net 6 core and it works as intended. However, i tried to the prototype code in Blazor Wasm `@page "/fetchdata" @code {
{
}) |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
-
The possibly best solution is to include fonts files as embedded resources and then loading them as streams 😁 Embedded resources are included in the final binary, so it makes sure that they are always available. |
Beta Was this translation helpful? Give feedback.
-
True, though that may have a side effect of slowing down the initial page load if the fonts are particularly big |
Beta Was this translation helpful? Give feedback.
-
@MarcinZiabek I tried Using QuestPDF in Blazor but I'm getting error. Steps:
<PackageReference Include="QuestPDF" Version="2022.12.1" />
<PackageReference Include="SkiaSharp.Views.Blazor" Version="2.88.3" />
@page "/"
@using QuestPDF.Drawing;
@using QuestPDF.Fluent;
@using QuestPDF.Helpers;
@inject HttpClient Http;
@if (Base64String is not null)
{
<iframe src="@($"data:application/pdf;base64,{Base64String}")"></iframe>
}
@code {
protected string? Base64String { get; set; }
private const string _font = "NotoSansSmall";
protected async override Task OnInitializedAsync()
//protected override void OnInitialized()
{
FontManager.RegisterFont(await Http.GetStreamAsync(@"http://localhost:5119/NotoSansSmall.ttf"));
//FontManager.RegisterFont(File.OpenRead(@"NotoSansSmall.ttf"));
var document = Document.Create(container =>
{
container.Page(page =>
{
page.ContinuousSize(3, QuestPDF.Infrastructure.Unit.Inch);
page.MarginVertical(5);
page.MarginHorizontal(10);
// page content
page
.Content()
.AlignCenter()
.Column(column =>
{
column
.Item()
.AlignCenter()
.Text(text =>
{
text.Line("Address: https://ilovedotnet.org")
.Italic();
text.Line("Description: Interactive .NET Knowledge Sharing Platform with In Browser Demos");
});
column
.Item()
.LineHorizontal(1)
.LineColor(Colors.Grey.Medium);
column
.Item()
.PaddingTop(5)
.PaddingBottom(-10)
.AlignCenter()
.Text(text =>
{
text.Line("Abdul Rahman").Bold();
});
column
.Item()
.LineHorizontal(1)
.LineColor(Colors.Grey.Medium);
column
.Item()
.PaddingTop(5)
.PaddingBottom(-10)
.AlignCenter()
.Text(text =>
{
text.Line("Frequency: Weekly Once");
text.Line("Day: Every Sunday");
text.Line("Payment Mode: Free");
text.Line("Active Users: 1500+");
text.Line("Owned By: Abdul Rahman");
text.Line("Powered By: .NET");
});
column
.Item()
.LineHorizontal(1)
.LineColor(Colors.Grey.Medium);
column
.Item()
.PaddingVertical(10)
.Table(table =>
{
table.ColumnsDefinition(columns =>
{
columns.RelativeColumn(8);
columns.RelativeColumn(2);
});
table.Cell().Text("Channel").Bold();
table.Cell().AlignRight().Text("Article Count").Bold();
table.Cell().PaddingVertical(5).LineHorizontal(1).LineColor(Colors.Grey.Medium);
table.Cell().PaddingVertical(5).LineHorizontal(1).LineColor(Colors.Grey.Medium);
table.Cell().Text("Total").Bold();
table.Cell().AlignRight().Text("58").Bold();
});
column
.Item()
.LineHorizontal(1)
.LineColor(Colors.Grey.Medium);
column
.Item()
.PaddingTop(10)
.AlignCenter()
.Text(text =>
{
text.Line("Thank you for reading");
text.Line("This is a computer generated receipt");
text.Line("This site is built by Bhai");
text.Line("And I Love .NET");
});
});
});
});
document.WithMetadata(new QuestPDF.Drawing.DocumentMetadata
{
Title = "Articles Summary",
Author = "Abdul Rahman",
Creator = "I Love .NET",
PdfA = true
});
//Base64String = document.GenerateImages().First().ToString();
using var memstream = new MemoryStream();
document.GeneratePdf(memstream);
Base64String = Convert.ToBase64String(memstream.ToArray());
}
} I get the following Error:
Please assist me on this. I'm planning to write an article showing usage of QuestPDF in blazor wasm. But got stuck with this issue. |
Beta Was this translation helpful? Give feedback.
The possibly best solution is to include fonts files as embedded resources and then loading them as streams 😁 Embedded resources are included in the final binary, so it makes sure that they are always available.