Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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.2</Version>
<Version>9.0.3</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
20 changes: 17 additions & 3 deletions src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public partial class PdfViewer
/// Gets or sets whether to use Google Docs for PDF rendering. Default is false.
/// </summary>
[Parameter]
public bool UseGoogleDocs { get; set; } = false;
public bool UseGoogleDocs { get; set; }

[Inject, NotNull]
private NavigationManager? NavigationManager { get; set; }
Comment thread
ArgoZhang marked this conversation as resolved.

private string? ClassString => CssBuilder.Default("bb-pdf-viewer-container")
.AddClassFromAttributes(AdditionalAttributes)
Expand Down Expand Up @@ -85,7 +88,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

if (rerender)
{
await InvokeVoidAsync("loadPdf", Id, _url);
await InvokeVoidAsync("loadPdf", Id, GetAbsoluteUri(_url));
}
}

Expand All @@ -97,9 +100,20 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
LoadedCallaback = nameof(TriggerOnLoaded),
NotSupportCallback = nameof(TriggerNotSupportCallback),
Url
Url = GetAbsoluteUri(Url)
});

private string GetAbsoluteUri(string? url)
{
url ??= string.Empty;
if (string.IsNullOrEmpty(url) || !UseGoogleDocs)
{
return url;
}
var uri = NavigationManager.ToAbsoluteUri(url);
return uri.AbsoluteUri;
}

/// <summary>
/// Trigger OnLoaded callback when the PDF document is loaded.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function loadPdf(id, url) {

const useGoogleDocs = el.getAttribute('data-bb-google-docs') === 'true';
if (useGoogleDocs) {
url = `https://docs.google.com/viewer?url=${url}`
url = `https://docs.google.com/viewer?url=${url}&embedded=true`
Comment thread
ArgoZhang marked this conversation as resolved.
}
viewer.src = url;
}
Expand Down