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>10.0.4</Version>
<Version>10.0.6</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
37 changes: 0 additions & 37 deletions src/components/BootstrapBlazor.PdfReader/EnumPageMode.cs

This file was deleted.

106 changes: 0 additions & 106 deletions src/components/BootstrapBlazor.PdfReader/EnumZoomMode.cs

This file was deleted.

30 changes: 15 additions & 15 deletions src/components/BootstrapBlazor.PdfReader/PdfReader.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,43 @@
@inherits BootstrapModuleComponentBase

<div @attributes="@AdditionalAttributes" id="@Id" class="@ClassString" style="@StyleString">
@if (ShowToolbar)
{
<div class="bb-view-toolbar">
<div class="bb-view-toolbar">
@if (ShowToolbar)
{
<div class="bb-view-group bb-view-title">
@if (EnableThumbnails)
{
<div class="bb-view-icon bb-view-bar" title="@Localizer["ToggleSidebar"]"><i class="fa-solid fa-bars"></i></div>
}
<span class="bb-view-subject">@_docTitle</span>
</div>
<div class="@ViewBodyString">
<div class="bb-view-group bb-view-toolbar-main">
<div class="bb-view-group bb-view-group-page">
<input type="text" class="bb-view-num" @bind="CurrentPageString" /><span class="bb-view-slash">/</span>
<input type="text" class="bb-view-num" value="1" /><span class="bb-view-slash">/</span>
<div class="bb-view-pagesCount"></div>
</div>
<div class="bb-view-group bb-view-group-scale">
<div class="bb-view-divider"></div>
<div class="bb-view-icon bb-page-minus" title="@Localizer["ZoomOut"]"><i class="fa-solid fa-fw fa-minus"></i></div>
<input type="text" class="bb-view-scale-input" @bind="CurrentScaleString" />
<input type="text" class="bb-view-scale-input" value="100%" />
<div class="bb-view-icon bb-page-plus" title="@Localizer["ZoomIn"]"><i class="fa-solid fa-fw fa-plus"></i></div>
</div>
<div class="bb-view-group bb-view-group-rotate">
<div class="bb-view-divider"></div>
<div class="bb-view-icon btn-group">
<button type="button" class="btn bb-view-fit-height" title="@Localizer["FitHeight"]" @onclick="() => SetFitMode(PdfReaderFitMode.PageHeight)"><i class="fa-solid fa-fw fa-arrows-left-right-to-line fa-rotate-90"></i></button>
<button type="button" class="btn bb-view-fit-width" title="@Localizer["FitWidth"]" @onclick="() => SetFitMode(PdfReaderFitMode.PageWidth)"><i class="fa-solid fa-fw fa-arrows-left-right-to-line"></i></button>
<button type="button" class="btn bb-view-fit-height" title="@Localizer["FitHeight"]"><i class="fa-solid fa-fw fa-arrows-left-right-to-line fa-rotate-90"></i></button>
<button type="button" class="btn bb-view-fit-width" title="@Localizer["FitWidth"]"><i class="fa-solid fa-fw fa-arrows-left-right-to-line"></i></button>
<button type="button" class="btn dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<div class="dropdown-menu dropdown-menu-end shadow">
<div class="dropdown-item" @onclick="() => SetFitMode(PdfReaderFitMode.PageActual)">@Localizer["PageActual"]</div>
<div class="dropdown-item" @onclick="() => SetFitMode(PdfReaderFitMode.PageWidth)">@Localizer["FitWidth"]</div>
<div class="dropdown-item" @onclick="() => SetFitMode(PdfReaderFitMode.PageHeight)">@Localizer["FitHeight"]</div>
<div class="dropdown-item bb-view-page-actual">@Localizer["PageActual"]</div>
<div class="dropdown-item bb-view-fit-width">@Localizer["FitWidth"]</div>
<div class="dropdown-item bb-view-fit-height">@Localizer["FitHeight"]</div>
</div>
</div>
<div class="bb-view-icon bb-view-fit-rotate" title="@Localizer["RotateLeft"]" @onclick="RotateLeft"><i class="fa-solid fa-fw fa-rotate-left"></i></div>
<div class="bb-view-icon bb-view-fit-rotate" title="@Localizer["RotateRight"]" @onclick="RotateRight"><i class="fa-solid fa-fw fa-rotate-right"></i></div>
<div class="bb-view-icon bb-view-rotate-left" title="@Localizer["RotateLeft"]"><i class="fa-solid fa-fw fa-rotate-left"></i></div>
<div class="bb-view-icon bb-view-rotate-right" title="@Localizer["RotateRight"]"><i class="fa-solid fa-fw fa-rotate-right"></i></div>
</div>
</div>
<div class="bb-view-group bb-view-controls">
Expand Down Expand Up @@ -83,8 +83,8 @@
</div>
</div>
</div>
</div>
}
}
</div>
<div class="bb-view-main">
@if (EnableThumbnails)
{
Expand Down
82 changes: 14 additions & 68 deletions src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using System.Globalization;

namespace BootstrapBlazor.Components;

Expand Down Expand Up @@ -135,57 +134,13 @@ public partial class PdfReader
.AddClassFromAttributes(AdditionalAttributes)
.Build();

private string? ViewBodyString => CssBuilder.Default("bb-view-group bb-view-toolbar-main")
.AddClass("fit-width", FitMode == PdfReaderFitMode.PageHeight)
.Build();

private string? _docTitle;
private PdfReaderFitMode _fitMode;
private uint _currentPage;
private string? _url;
private string? _currentScale;
private string? _dropdownItemCheckIcon;
private string? _dropdownItemDefaultIcon;
private bool _enableThumbnails = true;

private string CurrentPageString
{
get => CurrentPage.ToString(CultureInfo.InvariantCulture);
set => SetCurrentPage(value);
}

private void SetCurrentPage(string value)
{
if (uint.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var num))
{
CurrentPage = num;
}
}

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

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

CurrentScale = v.ToString(CultureInfo.InvariantCulture);
}
}
private bool _showToolbar = true;

/// <summary>
/// <inheritdoc/>
Expand Down Expand Up @@ -216,33 +171,29 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

if (firstRender)
{
_fitMode = FitMode;
_currentPage = CurrentPage;
_url = Url;
_currentScale = CurrentScale;
_currentPage = CurrentPage;
_enableThumbnails = EnableThumbnails;
_showToolbar = ShowToolbar;
}

if (_url != Url)
{
_url = Url;
await InvokeInitAsync();
}

if (_fitMode != FitMode)
{
_fitMode = FitMode;
await InvokeVoidAsync("setScaleValue", Id, _fitMode.ToDescriptionString());
}
if (_currentPage != CurrentPage)
{
_currentPage = CurrentPage;
await NavigateToPageAsync(_currentPage);
}
if (_currentScale != CurrentScale)
if (_showToolbar != ShowToolbar)
{
_currentScale = CurrentScale;
await InvokeVoidAsync("scale", Id, _currentScale);
_showToolbar = ShowToolbar;
if (_showToolbar)
{
await InvokeVoidAsync("resetToolbar", Id);
}
}
if (_enableThumbnails != EnableThumbnails)
{
Expand All @@ -263,6 +214,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
Url,
FitMode,
EnableThumbnails,
CurrentPage,
TriggerPagesInit = OnPagesInitAsync != null,
TriggerPagesLoaded = OnPagesLoadedAsync != null,
TriggerPageChanged = OnPageChangedAsync != null,
Expand All @@ -277,27 +229,21 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
public Task NavigateToPageAsync(uint pageNumber) => InvokeVoidAsync("navigateToPage", Id, pageNumber);

/// <summary>
/// 适应页面宽度
/// 设置页面适配模式方法
/// </summary>
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

Missing parameter documentation: The mode parameter is not documented. Add a <param name="mode"> tag to describe the fit mode parameter.

Suggested change
/// </summary>
/// </summary>
/// <param name="mode">页面适配模式,指定 PDF 阅读器的页面显示方式。</param>

Copilot uses AI. Check for mistakes.
public void SetFitMode(PdfReaderFitMode mode) => FitMode = mode;
public Task SetFitMode(PdfReaderFitMode mode) => InvokeVoidAsync("setScaleValue", Id, mode.ToDescriptionString());
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

Breaking API change: SetFitMode was changed from a synchronous method (void) to an asynchronous method (Task). This will break existing code that calls this method without awaiting. Consider adding an Async suffix to follow .NET naming conventions (e.g., SetFitModeAsync) or keeping the original synchronous signature and adding a new async version.

Suggested change
public Task SetFitMode(PdfReaderFitMode mode) => InvokeVoidAsync("setScaleValue", Id, mode.ToDescriptionString());
public Task SetFitModeAsync(PdfReaderFitMode mode) => InvokeVoidAsync("setScaleValue", Id, mode.ToDescriptionString());

Copilot uses AI. Check for mistakes.

/// <summary>
/// 旋转页面方法
/// </summary>
/// <returns></returns>
public async Task RotateLeft()
{
await InvokeVoidAsync("rotate", Id, -90);
}
public Task RotateLeft() => InvokeVoidAsync("rotate", Id, -90);

/// <summary>
/// 旋转页面方法
/// </summary>
/// <returns></returns>
public async Task RotateRight()
{
await InvokeVoidAsync("rotate", Id, 90);
}
public Task RotateRight() => InvokeVoidAsync("rotate", Id, 90);

private async Task OnDownload()
{
Expand Down
4 changes: 2 additions & 2 deletions src/components/BootstrapBlazor.PdfReader/PdfReader.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@
width: 1%;
}

.bb-view-toolbar-main.fit-width .bb-view-fit-height {
.bb-view-toolbar-main .fit-height .bb-view-fit-height {
display: none;
}

.bb-view-toolbar-main.fit-width .bb-view-fit-width {
.bb-view-toolbar-main .fit-height .bb-view-fit-width {
display: block;
}
Comment on lines +82 to 88
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

The CSS selector .bb-view-toolbar-main .fit-height .bb-view-fit-height expects a .fit-height class on an element between .bb-view-toolbar-main and the button. However, in the Razor markup (line 27-28), the .fit-height class is applied to .bb-view-group-rotate, not directly to .bb-view-toolbar-main. The selector should be .bb-view-toolbar-main .bb-view-group-rotate.fit-height .bb-view-fit-height to match the actual DOM structure.

Copilot uses AI. Check for mistakes.

Expand Down
Loading
Loading