Skip to content

Commit ff78f2b

Browse files
committed
Committing the Blazor sample
1 parent 76e5f18 commit ff78f2b

37 files changed

+1439
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34330.188
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Use-alternate-font-without-installing", "Use-alternate-font-without-installing\Use-alternate-font-without-installing.csproj", "{A3D46D19-CBC7-49DF-B41B-C01E33FD30A6}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{A3D46D19-CBC7-49DF-B41B-C01E33FD30A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{A3D46D19-CBC7-49DF-B41B-C01E33FD30A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{A3D46D19-CBC7-49DF-B41B-C01E33FD30A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{A3D46D19-CBC7-49DF-B41B-C01E33FD30A6}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {0C2166EC-133F-4E11-B5CE-123CC2CCBEC0}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Router AppAssembly="@typeof(App).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
5+
</Found>
6+
<NotFound>
7+
<PageTitle>Not found</PageTitle>
8+
<LayoutView Layout="@typeof(MainLayout)">
9+
<p role="alert">Sorry, there's nothing at this address.</p>
10+
</LayoutView>
11+
</NotFound>
12+
</Router>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Microsoft.JSInterop;
2+
3+
namespace Use_alternate_font_without_installing
4+
{
5+
public static class FileUtils
6+
{
7+
public static ValueTask<object> SaveAs(this IJSRuntime js, string filename, byte[] data)
8+
=> js.InvokeAsync<object>(
9+
"saveAsFile",
10+
filename,
11+
Convert.ToBase64String(data));
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Reflection;
2+
3+
namespace Use_alternate_font_without_installing
4+
{
5+
public class HelperService
6+
{
7+
/// <summary>
8+
/// Gets the embedded font stream.
9+
/// </summary>
10+
/// <param name="fontName">Represent the name of the font stream.</param>
11+
/// <returns>Returns the font stream of given font name, if it is embedded. Otherwise returns null.</returns>
12+
public Stream GetFontStream(string fontName)
13+
{
14+
Assembly assembly = Assembly.GetExecutingAssembly();
15+
//fontName = fontName.ToLower() + ".ttf";
16+
foreach (string resourceName in assembly.GetManifestResourceNames())
17+
{
18+
if (resourceName.ToLower().EndsWith(fontName))
19+
{
20+
Stream fontStream = assembly.GetManifestResourceStream(resourceName);
21+
if (fontStream != null)
22+
{
23+
fontStream.Position = 0;
24+
return fontStream;
25+
}
26+
}
27+
}
28+
return null;
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@page "/counter"
2+
3+
<PageTitle>Counter</PageTitle>
4+
5+
<h1>Counter</h1>
6+
7+
<p role="status">Current count: @currentCount</p>
8+
9+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
10+
11+
@code {
12+
private int currentCount = 0;
13+
14+
private void IncrementCount()
15+
{
16+
currentCount++;
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
@page "/docio"
2+
@inject Microsoft.JSInterop.IJSRuntime JS
3+
@inject HttpClient client
4+
@using Syncfusion.DocIO
5+
@using Syncfusion.Drawing
6+
@using Syncfusion.Pdf
7+
@using Syncfusion.DocIORenderer
8+
@using Syncfusion.DocIO.DLS
9+
@using System.IO
10+
@inject HelperService service;
11+
12+
<h2>Syncfusion DocIO library (Essential DocIO)</h2>
13+
<p>Syncfusion Blazor DocIO library (Essential DocIO) used to create, read, edit, and convert DocIO files in your applications without Microsoft Office dependencies.</p>
14+
<button class="btn btn-primary" @onclick="@WordToPDF">Convert Word to PDF</button>
15+
16+
@functions {
17+
async void WordToPDF()
18+
{
19+
using (Stream inputStream = await client.GetStreamAsync("sample-data/Adventure.docx"))
20+
{
21+
//Open an existing Word document.
22+
using (WordDocument document = new WordDocument(inputStream, FormatType.Automatic))
23+
{
24+
//Hooks the font substitution event
25+
document.FontSettings.SubstituteFont += FontSettings_SubstituteFont;
26+
//Initialize the DocIORenderer for Word to PDF conversion.
27+
using (DocIORenderer render = new DocIORenderer())
28+
{
29+
//Convert Word document into PDF document.
30+
using (PdfDocument pdfDocument = render.ConvertToPDF(document))
31+
{
32+
//Save the PDF document to MemoryStream.
33+
using (MemoryStream outputStream = new MemoryStream())
34+
{
35+
document.FontSettings.SubstituteFont -= FontSettings_SubstituteFont;
36+
pdfDocument.Save(outputStream);
37+
outputStream.Position = 0;
38+
//Download PDF file in the browser.
39+
await JS.SaveAs("Output.pdf", outputStream.ToArray());
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}
46+
private void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
47+
{
48+
if (args.OriginalFontName == "Times New Roman" && args.FontStyle == Syncfusion.Drawing.FontStyle.Regular)
49+
args.AlternateFontStream = service.GetFontStream("times.ttf");
50+
else if (args.OriginalFontName == "Times New Roman" && args.FontStyle == Syncfusion.Drawing.FontStyle.Bold)
51+
args.AlternateFontStream = service.GetFontStream("timesbd.ttf");
52+
else if (args.OriginalFontName == "Times New Roman" && args.FontStyle == Syncfusion.Drawing.FontStyle.Italic)
53+
args.AlternateFontStream = service.GetFontStream("timesi.ttf");
54+
else
55+
args.AlternateFontStream = service.GetFontStream("times.ttf");
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
@page "/fetchdata"
2+
@inject HttpClient Http
3+
4+
<PageTitle>Weather forecast</PageTitle>
5+
6+
<h1>Weather forecast</h1>
7+
8+
<p>This component demonstrates fetching data from the server.</p>
9+
10+
@if (forecasts == null)
11+
{
12+
<p><em>Loading...</em></p>
13+
}
14+
else
15+
{
16+
<table class="table">
17+
<thead>
18+
<tr>
19+
<th>Date</th>
20+
<th>Temp. (C)</th>
21+
<th>Temp. (F)</th>
22+
<th>Summary</th>
23+
</tr>
24+
</thead>
25+
<tbody>
26+
@foreach (var forecast in forecasts)
27+
{
28+
<tr>
29+
<td>@forecast.Date.ToShortDateString()</td>
30+
<td>@forecast.TemperatureC</td>
31+
<td>@forecast.TemperatureF</td>
32+
<td>@forecast.Summary</td>
33+
</tr>
34+
}
35+
</tbody>
36+
</table>
37+
}
38+
39+
@code {
40+
private WeatherForecast[]? forecasts;
41+
42+
protected override async Task OnInitializedAsync()
43+
{
44+
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
45+
}
46+
47+
public class WeatherForecast
48+
{
49+
public DateTime Date { get; set; }
50+
51+
public int TemperatureC { get; set; }
52+
53+
public string? Summary { get; set; }
54+
55+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@page "/"
2+
3+
<PageTitle>Index</PageTitle>
4+
5+
<h1>Hello, world!</h1>
6+
7+
Welcome to your new app.
8+
9+
<SurveyPrompt Title="How is Blazor working for you?" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.AspNetCore.Components.Web;
2+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
3+
using Use_alternate_font_without_installing;
4+
5+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
6+
builder.RootComponents.Add<App>("#app");
7+
builder.RootComponents.Add<HeadOutlet>("head::after");
8+
9+
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
10+
builder.Services.AddSingleton<HelperService>();
11+
await builder.Build().RunAsync();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:59915",
7+
"sslPort": 44372
8+
}
9+
},
10+
"profiles": {
11+
"Use-alternate-font-without-installing": {
12+
"commandName": "Project",
13+
"dotnetRunMessages": true,
14+
"launchBrowser": true,
15+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
16+
"applicationUrl": "https://localhost:7253;http://localhost:5212",
17+
"environmentVariables": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
}
20+
},
21+
"IIS Express": {
22+
"commandName": "IISExpress",
23+
"launchBrowser": true,
24+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
25+
"environmentVariables": {
26+
"ASPNETCORE_ENVIRONMENT": "Development"
27+
}
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)