-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathHome.razor
More file actions
38 lines (33 loc) · 1.35 KB
/
Home.razor
File metadata and controls
38 lines (33 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@page "/"
@inject IJSRuntime JSRuntime
<SfPdfViewer2 @ref="PdfViewer" DocumentPath="@DocumentPath" Height="100%" Width="100%">
<PdfViewerEvents DocumentLoaded="OnDocumentLoaded" DocumentUnloaded="OnDocumentUnloaded"
OnTextSelectionEnd="HandleTextSelectionEnd" />
</SfPdfViewer2>
@code
{
// Reference to the PDF Viewer component
private SfPdfViewer2? PdfViewer;
// Path to the PDF document to be loaded in the viewer
private string DocumentPath = "https://cdn.syncfusion.com/content/pdf/programmatical-annotations.pdf";
// Triggered when the document is unloaded from the viewer
private async Task OnDocumentUnloaded()
{
// Calls a JavaScript function to cancel any ongoing reading process
await JSRuntime.InvokeVoidAsync("cancelReading");
}
// Triggered when the document is loaded in the viewer
private async Task OnDocumentLoaded()
{
// Calls a JavaScript function to initialize PDF accessibility features
await JSRuntime.InvokeVoidAsync("initPdfAccessibility");
}
// Triggered when text selection ends in the PDF Viewer
private async Task HandleTextSelectionEnd(TextSelectionEndEventArgs args)
{
if (!string.IsNullOrEmpty(args.TextContent))
{
await JSRuntime.InvokeVoidAsync("readAloudText", args.TextContent);
}
}
}