Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.0.0-beta01</Version>
<Version>9.0.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
44 changes: 43 additions & 1 deletion src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ public partial class PdfViewer
[Parameter]
public string? Height { get; set; }

/// <summary>
/// Gets or sets the document loaded event callback.
/// </summary>
[Parameter]
public Func<Task>? OnLoaded { get; set; }
Comment thread
ArgoZhang marked this conversation as resolved.

/// <summary>
/// Gets or sets the document loaded event callback.
/// </summary>
[Parameter]
public Func<Task>? NotSupportCallback { get; set; }
Comment thread
ArgoZhang marked this conversation as resolved.

private string? ClassString => CssBuilder.Default("bb-pdf-viewer-container")
.AddClassFromAttributes(AdditionalAttributes)
.Build();
Expand Down Expand Up @@ -58,5 +70,35 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
/// <inheritdoc/>
/// </summary>
/// <returns></returns>
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id);
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, new
{
LoadedCallaback = nameof(TriggerOnLoaded),
NotSupportCallback = nameof(TriggerNotSupportCallback)
});
Comment thread
ArgoZhang marked this conversation as resolved.

/// <summary>
/// Trigger OnLoaded callback when the PDF document is loaded.
/// </summary>
/// <returns></returns>
[JSInvokable]
public async Task TriggerOnLoaded()
{
if (OnLoaded != null)
{
await OnLoaded();
}
}

/// <summary>
/// Trigger NotSupportCallback when the PDF viewer does not support the document.
/// </summary>
/// <returns></returns>
[JSInvokable]
public async Task TriggerNotSupportCallback()
{
if (NotSupportCallback != null)
{
await NotSupportCallback();
}
}
}
15 changes: 12 additions & 3 deletions src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { addLink } from "../BootstrapBlazor/modules/utility.js"
import Data from "../BootstrapBlazor/modules/data.js"

export async function init(id) {
export async function init(id, invoke, options) {
await addLink("./_content/BootstrapBlazor.PdfViewer/pdf-viewer.css");

if (!navigator.pdfViewerEnabled) {
await invoke.invokeMethodAsync(options.notSupportCallback);
}
Comment thread
ArgoZhang marked this conversation as resolved.
Outdated

const el = document.getElementById(id);
const pdfViewer = { el };
const pdfViewer = { el, invoke, options };
Data.set(id, pdfViewer);

const url = el.getAttribute('data-bb-url');
Expand All @@ -16,8 +20,13 @@ export function loadPdf(id, url) {
const pdfViewer = Data.get(id);
const { el } = pdfViewer;
if (url) {
const { frame } = pdfViewer;
const { frame, invoke, options } = pdfViewer;
const viewer = frame || createFrame(el);
if (options.loadedCallaback) {
viewer.onload = () => {
invoke.invokeMethodAsync(options.loadedCallaback);
};
}
Comment thread
ArgoZhang marked this conversation as resolved.
viewer.src = url;
}
else {
Expand Down