Skip to content

Commit 2b9a285

Browse files
authored
feat(PdfViewer): add PageIndex parameter (#506)
* feat: 增加 PageIndex 参数 * chore: bump version 9.0.4 * chore: 支持页码变化重新渲染 * chore: bump version 9.0.5
1 parent f25fd3d commit 2b9a285

2 files changed

Lines changed: 10 additions & 27 deletions

File tree

src/components/BootstrapBlazor.PdfViewer/BootstrapBlazor.PdfViewer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.0.3</Version>
4+
<Version>9.0.5</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>

src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.cs

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ public partial class PdfViewer
1717
[Parameter]
1818
public string? Url { get; set; }
1919

20+
/// <summary>
21+
/// Gets or sets the page index of the PDF file.
22+
/// </summary>
23+
[Parameter]
24+
public int PageIndex { get; set; }
25+
2026
/// <summary>
2127
/// Gets or sets the viewer height. Default is null.
2228
/// </summary>
@@ -52,9 +58,6 @@ public partial class PdfViewer
5258
.AddClass($"--bb-pdf-viewer-height: {Height};", !string.IsNullOrEmpty(Height))
5359
.Build();
5460

55-
private string? _url;
56-
private bool _useGoogleDocs;
57-
5861
private string? UseGoogleDocsString => UseGoogleDocs ? "true" : null;
5962

6063
/// <summary>
@@ -66,29 +69,9 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
6669
{
6770
await base.OnAfterRenderAsync(firstRender);
6871

69-
if (firstRender)
70-
{
71-
_url = Url;
72-
_useGoogleDocs = UseGoogleDocs;
73-
return;
74-
}
75-
76-
var rerender = false;
77-
if (_url != Url)
78-
{
79-
_url = Url;
80-
rerender = true;
81-
}
82-
83-
if (_useGoogleDocs != UseGoogleDocs)
84-
{
85-
_useGoogleDocs = UseGoogleDocs;
86-
rerender = true;
87-
}
88-
89-
if (rerender)
72+
if (!firstRender)
9073
{
91-
await InvokeVoidAsync("loadPdf", Id, GetAbsoluteUri(_url));
74+
await InvokeVoidAsync("loadPdf", Id, GetAbsoluteUri(Url));
9275
}
9376
}
9477

@@ -108,7 +91,7 @@ private string GetAbsoluteUri(string? url)
10891
url ??= string.Empty;
10992
if (string.IsNullOrEmpty(url) || !UseGoogleDocs)
11093
{
111-
return url;
94+
return $"{url}#page={PageIndex}";
11295
}
11396
var uri = NavigationManager.ToAbsoluteUri(url);
11497
return uri.AbsoluteUri;

0 commit comments

Comments
 (0)