-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(PdfViewer): add PageIndex parameter #506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,12 @@ public partial class PdfViewer | |
| [Parameter] | ||
| public string? Url { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the page index of the PDF file. | ||
| /// </summary> | ||
| [Parameter] | ||
| public int PageIndex { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the viewer height. Default is null. | ||
| /// </summary> | ||
|
|
@@ -52,9 +58,6 @@ public partial class PdfViewer | |
| .AddClass($"--bb-pdf-viewer-height: {Height};", !string.IsNullOrEmpty(Height)) | ||
| .Build(); | ||
|
|
||
| private string? _url; | ||
| private bool _useGoogleDocs; | ||
|
|
||
| private string? UseGoogleDocsString => UseGoogleDocs ? "true" : null; | ||
|
|
||
| /// <summary> | ||
|
|
@@ -66,29 +69,9 @@ protected override async Task OnAfterRenderAsync(bool firstRender) | |
| { | ||
| await base.OnAfterRenderAsync(firstRender); | ||
|
|
||
| if (firstRender) | ||
| { | ||
| _url = Url; | ||
| _useGoogleDocs = UseGoogleDocs; | ||
| return; | ||
| } | ||
|
|
||
| var rerender = false; | ||
| if (_url != Url) | ||
| { | ||
| _url = Url; | ||
| rerender = true; | ||
| } | ||
|
|
||
| if (_useGoogleDocs != UseGoogleDocs) | ||
| { | ||
| _useGoogleDocs = UseGoogleDocs; | ||
| rerender = true; | ||
| } | ||
|
|
||
| if (rerender) | ||
| if (!firstRender) | ||
| { | ||
| await InvokeVoidAsync("loadPdf", Id, GetAbsoluteUri(_url)); | ||
| await InvokeVoidAsync("loadPdf", Id, GetAbsoluteUri(Url)); | ||
| } | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Appending '#page={PageIndex}' to all URLs may break some PDF viewers or integrations. Some viewers or contexts may not handle the '#page=' fragment correctly. Consider making this addition optional or context-aware. Suggested implementation: url ??= string.Empty;
// Add an optional parameter to control appending the page fragment
return GetProcessedUrl(url, appendPageFragment: false);
}
private string GetProcessedUrl(string url, bool appendPageFragment = false)
{
if (string.IsNullOrEmpty(url) || !UseGoogleDocs)
{
if (appendPageFragment)
{
return $"{url}#page={PageIndex}";
}
return url;
}
var uri = NavigationManager.ToAbsoluteUri(url);
if (appendPageFragment)
{
return $"{uri.AbsoluteUri}#page={PageIndex}";
}
return uri.AbsoluteUri;You will need to update all usages of this code to call |
||
|
|
@@ -108,7 +91,7 @@ private string GetAbsoluteUri(string? url) | |
| url ??= string.Empty; | ||
| if (string.IsNullOrEmpty(url) || !UseGoogleDocs) | ||
| { | ||
| return url; | ||
| return $"{url}#page={PageIndex}"; | ||
| } | ||
| var uri = NavigationManager.ToAbsoluteUri(url); | ||
| return uri.AbsoluteUri; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider defaulting PageIndex to 1 to avoid invalid PDF page references.
Defaulting to 1 aligns with standard PDF viewer behavior and helps prevent errors from invalid page references.