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
10 changes: 5 additions & 5 deletions src/components/BootstrapBlazor.PdfReader/PdfReader.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<div class="@ViewBodyString">
<input type="text" class="bb-view-num" @bind="CurrentPageString" /><span class="bb-view-slash">/</span><div class="bb-view-pagesCount"></div>
<div class="bb-view-divider"></div>
<div class="bb-view-icon"><i class="fa-solid fa-minus"></i></div>
<input type="text" class="bb-view-scale" value="100%" />
<div class="bb-view-icon"><i class="fa-solid fa-plus"></i></div>
<div class="bb-view-icon bb-page-minus"><i class="fa-solid fa-minus"></i></div>
<input type="text" class="bb-view-scale" @bind="CurrentScaleString" />
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): The JS-driven scale changes don’t propagate back to the Blazor-bound CurrentScaleString, which can desync component state.

The scalechanging handler updates scaleEl.value but never fires input/change or calls back into .NET, so Blazor is unaware of zoom changes made via the buttons or viewer controls. That means CurrentScaleString / _currentScale / Options.CurrentScale can diverge from the actual viewer scale. To keep them in sync, either dispatch an input event on scaleEl after updating it, or invoke a .NET method from JS (like pageChanged) to update Options.CurrentScale.

Suggested implementation:

eventBus.on('scalechanging', function (evt) {
    var predefinedValue = evt.presetValue || evt.scale;
    var scaleSelect = container.querySelector('.bb-view-scale');
    if (!scaleSelect) {
        return;
    }

    if (predefinedValue) {
        scaleSelect.value = predefinedValue;
    } else if (evt.scale) {
        scaleSelect.value = Math.round(evt.scale * 100) + '%';
    }

    // Ensure Blazor's @bind="CurrentScaleString" is updated when the scale is changed from JS
    try {
        if (typeof Event === 'function') {
            // Fire both input and change so any Blazor/value-change handlers are triggered
            scaleSelect.dispatchEvent(new Event('input', { bubbles: true }));
            scaleSelect.dispatchEvent(new Event('change', { bubbles: true }));
        }
    } catch (e) {
        // Fallback for very old browsers; Blazor apps generally don't target these, so no-op is fine
    }
});

Because I only see a fragment of the Razor markup and not the JavaScript block, you may need to adjust the SEARCH section to match your actual scalechanging handler. Concretely:

  1. Locate the code that subscribes to the PDF.js scalechanging event (or equivalent) inside PdfReader.razor (often in a <script> block or a referenced JS file if inlined via @Inject IJSRuntime).
  2. Within that handler, immediately after you assign to the .bb-view-scale element’s value (the element bound via @bind="CurrentScaleString"), add:
    • scaleSelect.dispatchEvent(new Event('input', { bubbles: true }));
    • scaleSelect.dispatchEvent(new Event('change', { bubbles: true }));
  3. Ensure that the query selector (container.querySelector('.bb-view-scale')) is targeting the same input you bound with @bind="CurrentScaleString"; if your variable is named scaleEl instead of scaleSelect, update the snippet accordingly.
  4. If your scalechanging handler currently uses different variable names or structure, keep the existing logic and only add the two dispatchEvent calls right after the value assignment to keep Blazor’s CurrentScaleString / _currentScale / Options.CurrentScale in sync with the actual viewer scale.

<div class="bb-view-icon bb-page-plus"><i class="fa-solid fa-plus"></i></div>
<div class="bb-view-divider"></div>
<div class="bb-view-icon bb-view-fit-page" @onclick="FitToPage"><i class="fa-solid fa-arrows-left-right-to-line"></i></div>
<div class="bb-view-icon bb-view-fit-width" @onclick="FitToWidth"><i class="fa-solid fa-arrows-left-right"></i></div>
<div class="bb-view-icon bb-view-fit-page" @onclick="FitToPage"><i class="fa-solid fa-arrows-left-right-to-line fa-rotate-90"></i></div>
<div class="bb-view-icon bb-view-fit-width" @onclick="FitToWidth"><i class="fa-solid fa-arrows-left-right-to-line"></i></div>
<div class="bb-view-icon bb-view-fit-rotate" @onclick="RotateLeft"><i class="fa-solid fa-rotate-left"></i></div>
<div class="bb-view-icon bb-view-fit-rotate" @onclick="RotateRight"><i class="fa-solid fa-rotate-right"></i></div>
<div class="bb-view-divider"></div>
Expand Down
36 changes: 36 additions & 0 deletions src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public partial class PdfReader
private bool _isFitToPage;
private uint _currentPage;
private string? _url;
private string? _currentScale;

private readonly HashSet<string> AllowedScaleValues = ["page-actual", "page-width", "page-height", "page-fit", "auto"];

Comment on lines +42 to 43
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AllowedScaleValues field is defined but never used. If this is intended for future validation of scale values (to allow special values like "page-actual", "page-width", etc.), it should be integrated into the SetCurrentScale method. Otherwise, it should be removed to avoid confusion.

Suggested change
private readonly HashSet<string> AllowedScaleValues = ["page-actual", "page-width", "page-height", "page-fit", "auto"];

Copilot uses AI. Check for mistakes.
private string CurrentPageString
{
Expand All @@ -52,6 +55,33 @@ private void SetCurrentPage(string value)
}
}

private string CurrentScaleString
{
get => $"{Options.CurrentScale ?? "100"}%";
set => SetCurrentScale(value);
}

private void SetCurrentScale(string value)
{
if (string.IsNullOrEmpty(value))
{
Options.CurrentScale = "100";
}
else if (float.TryParse(value.TrimEnd("%"), out var v))
{
if (v > 500)
{
v = 500;
}
else if (v < 25)
{
v = 25;
}

Options.CurrentScale = v.ToString(CultureInfo.InvariantCulture);
}
}

/// <summary>
/// <inheritdoc/>
/// </summary>
Expand Down Expand Up @@ -82,6 +112,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
_isFitToPage = Options.IsFitToPage;
_currentPage = Options.CurrentPage;
_url = Options.Url;
_currentScale = Options.CurrentScale;
}

if (_url != Options.Url)
Expand All @@ -100,6 +131,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
_currentPage = Options.CurrentPage;
await NavigateToPageAsync(_currentPage);
}
if (_currentScale != Options.CurrentScale)
{
_currentScale = Options.CurrentScale;
await InvokeVoidAsync("scale", Id, _currentScale);
}
}

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions src/components/BootstrapBlazor.PdfReader/PdfReader.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
cursor: pointer;
}

.bb-view-icon.disabled {
color: #6c757d;
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .bb-view-icon.disabled class only changes the color but still maintains cursor: pointer from the parent .bb-view-icon rule (line 31). When an icon is disabled, the cursor should be changed to cursor: not-allowed or cursor: default to provide better visual feedback to users.

Suggested change
color: #6c757d;
color: #6c757d;
cursor: not-allowed;

Copilot uses AI. Check for mistakes.
}

.bb-view-bar {
margin-inline-end: 2rem;
}
Expand Down
Loading
Loading