Skip to content

Commit 61300bb

Browse files
authored
Merge pull request #32 from PSPDFKit/shan/update-blazor-example
Update blazor example to .NET 8 Blazor templates
2 parents d4ac2bd + 6336578 commit 61300bb

File tree

73 files changed

+920
-20625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+920
-20625
lines changed

examples/blazor/.gitignore

Lines changed: 412 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36221.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nutrient-BlazorServer", "Nutrient-BlazorServer\Nutrient-BlazorServer.csproj", "{9A460DB3-FFA5-4DBE-B535-66882696BAAF}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nutrient-BlazorWASM", "Nutrient-BlazorWASM\Nutrient-BlazorWASM\Nutrient-BlazorWASM.csproj", "{1BCB3380-02EF-4586-B3E8-7C701EBAC858}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nutrient-BlazorWASM.Client", "Nutrient-BlazorWASM\Nutrient-BlazorWASM.Client\Nutrient-BlazorWASM.Client.csproj", "{F3111550-3A64-426B-8C39-FB32334BF4C7}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Release|Any CPU = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{9A460DB3-FFA5-4DBE-B535-66882696BAAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{9A460DB3-FFA5-4DBE-B535-66882696BAAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{9A460DB3-FFA5-4DBE-B535-66882696BAAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{9A460DB3-FFA5-4DBE-B535-66882696BAAF}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{1BCB3380-02EF-4586-B3E8-7C701EBAC858}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{1BCB3380-02EF-4586-B3E8-7C701EBAC858}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{1BCB3380-02EF-4586-B3E8-7C701EBAC858}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{1BCB3380-02EF-4586-B3E8-7C701EBAC858}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{F3111550-3A64-426B-8C39-FB32334BF4C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{F3111550-3A64-426B-8C39-FB32334BF4C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{F3111550-3A64-426B-8C39-FB32334BF4C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{F3111550-3A64-426B-8C39-FB32334BF4C7}.Release|Any CPU.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {3DA9C8F6-0D45-466D-A92B-06663484C192}
36+
EndGlobalSection
37+
EndGlobal
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<base href="/" />
8+
<link rel="stylesheet" href="app.css" />
9+
<link rel="stylesheet" href="Nutrient-BlazorServer.styles.css" />
10+
<HeadOutlet />
11+
</head>
12+
13+
<body>
14+
<Routes />
15+
<script src="_framework/blazor.web.js"></script>
16+
@* Include nutrient-viewer.js in your Pages/_Host.cshtml file *@
17+
<script src=nutrient-viewer.js"></script>
18+
19+
@* Initialize Nutrient Viewer in Blazor Server by calling NutrientViewer.load(): *@
20+
<script>
21+
function loadPDF(container, document) {
22+
NutrientViewer.load({
23+
container: container,
24+
document: document
25+
})
26+
}
27+
</script>
28+
</body>
29+
30+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@inherits LayoutComponentBase
2+
3+
@Body
4+
5+
<div id="blazor-error-ui">
6+
An unhandled error has occurred.
7+
<a href="" class="reload">Reload</a>
8+
<a class="dismiss">🗙</a>
9+
</div>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#blazor-error-ui {
2+
background: lightyellow;
3+
bottom: 0;
4+
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
5+
display: none;
6+
left: 0;
7+
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
8+
position: fixed;
9+
width: 100%;
10+
z-index: 1000;
11+
}
12+
13+
#blazor-error-ui .dismiss {
14+
cursor: pointer;
15+
position: absolute;
16+
right: 0.75rem;
17+
top: 0.5rem;
18+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@page "/Error"
2+
@using System.Diagnostics
3+
4+
<PageTitle>Error</PageTitle>
5+
6+
<h1 class="text-danger">Error.</h1>
7+
<h2 class="text-danger">An error occurred while processing your request.</h2>
8+
9+
@if (ShowRequestId)
10+
{
11+
<p>
12+
<strong>Request ID:</strong> <code>@RequestId</code>
13+
</p>
14+
}
15+
16+
<h3>Development Mode</h3>
17+
<p>
18+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
19+
</p>
20+
<p>
21+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
22+
It can result in displaying sensitive information from exceptions to end users.
23+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
24+
and restarting the app.
25+
</p>
26+
27+
@code{
28+
[CascadingParameter]
29+
private HttpContext? HttpContext { get; set; }
30+
31+
private string? RequestId { get; set; }
32+
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
33+
34+
protected override void OnInitialized() =>
35+
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
36+
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
@page "/"
2-
@inject IJSRuntime JS
3-
4-
<div id='container' style='background: gray; width: 100vw; height: 100vh; margin: 0 auto;'></div>
5-
6-
@code {
7-
8-
protected override async void OnAfterRender(bool firstRender)
9-
{
10-
if (firstRender) {
11-
await JS.InvokeVoidAsync("loadPDF", "#container", "document.pdf");
12-
}
13-
}
14-
}
1+
@page "/"
2+
@rendermode InteractiveServer
3+
@inject IJSRuntime JS
4+
5+
<div id='container' style='background: gray; width: 100vw; height: 100vh; margin: 0 auto;'></div>
6+
7+
@code {
8+
9+
protected override async void OnAfterRender(bool firstRender)
10+
{
11+
if (firstRender)
12+
{
13+
await JS.InvokeVoidAsync("loadPDF", "#container", "document.pdf");
14+
}
15+
}
16+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Router AppAssembly="typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
4+
<FocusOnNavigate RouteData="routeData" Selector="h1" />
5+
</Found>
6+
</Router>
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
@using System.Net.Http
2-
@using Microsoft.AspNetCore.Authorization
3-
@using Microsoft.AspNetCore.Components.Authorization
2+
@using System.Net.Http.Json
43
@using Microsoft.AspNetCore.Components.Forms
54
@using Microsoft.AspNetCore.Components.Routing
65
@using Microsoft.AspNetCore.Components.Web
6+
@using static Microsoft.AspNetCore.Components.Web.RenderMode
77
@using Microsoft.AspNetCore.Components.Web.Virtualization
88
@using Microsoft.JSInterop
99
@using Nutrient_BlazorServer
10-
@using Nutrient_BlazorServer.Shared
10+
@using Nutrient_BlazorServer.Components
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<RootNamespace>Nutrient-BlazorServer</RootNamespace>
8+
<AssemblyName>$(AssemblyName.Replace(' ', '_'))</AssemblyName>
9+
</PropertyGroup>
10+
11+
</Project>

0 commit comments

Comments
 (0)