Skip to content

Commit 69d3be6

Browse files
authored
feat(PdfReader): add OnPageChangedAsync parameter (#719)
1 parent e0679ff commit 69d3be6

5 files changed

Lines changed: 114 additions & 240 deletions

File tree

src/components/BootstrapBlazor.PdfReader/PdfReader.razor

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
<div class="@ViewBodyString">
1414
<input type="text" class="bb-view-num" @bind="CurrentPageString" /><span class="bb-view-slash">/</span><div class="bb-view-pagesCount"></div>
1515
<div class="bb-view-divider"></div>
16-
<div class="bb-view-icon"><i class="fa-solid fa-minus"></i></div>
17-
<input type="text" class="bb-view-scale" value="100%" />
18-
<div class="bb-view-icon"><i class="fa-solid fa-plus"></i></div>
16+
<div class="bb-view-icon bb-page-minus"><i class="fa-solid fa-minus"></i></div>
17+
<input type="text" class="bb-view-scale" @bind="CurrentScaleString" />
18+
<div class="bb-view-icon bb-page-plus"><i class="fa-solid fa-plus"></i></div>
1919
<div class="bb-view-divider"></div>
20-
<div class="bb-view-icon bb-view-fit-page" @onclick="FitToPage"><i class="fa-solid fa-arrows-left-right-to-line"></i></div>
21-
<div class="bb-view-icon bb-view-fit-width" @onclick="FitToWidth"><i class="fa-solid fa-arrows-left-right"></i></div>
20+
<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>
21+
<div class="bb-view-icon bb-view-fit-width" @onclick="FitToWidth"><i class="fa-solid fa-arrows-left-right-to-line"></i></div>
2222
<div class="bb-view-icon bb-view-fit-rotate" @onclick="RotateLeft"><i class="fa-solid fa-rotate-left"></i></div>
2323
<div class="bb-view-icon bb-view-fit-rotate" @onclick="RotateRight"><i class="fa-solid fa-rotate-right"></i></div>
2424
<div class="bb-view-divider"></div>

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public partial class PdfReader
3737
private bool _isFitToPage;
3838
private uint _currentPage;
3939
private string? _url;
40+
private string? _currentScale;
41+
42+
private readonly HashSet<string> AllowedScaleValues = ["page-actual", "page-width", "page-height", "page-fit", "auto"];
4043

4144
private string CurrentPageString
4245
{
@@ -52,6 +55,33 @@ private void SetCurrentPage(string value)
5255
}
5356
}
5457

58+
private string CurrentScaleString
59+
{
60+
get => $"{Options.CurrentScale ?? "100"}%";
61+
set => SetCurrentScale(value);
62+
}
63+
64+
private void SetCurrentScale(string value)
65+
{
66+
if (string.IsNullOrEmpty(value))
67+
{
68+
Options.CurrentScale = "100";
69+
}
70+
else if (float.TryParse(value.TrimEnd("%"), out var v))
71+
{
72+
if (v > 500)
73+
{
74+
v = 500;
75+
}
76+
else if (v < 25)
77+
{
78+
v = 25;
79+
}
80+
81+
Options.CurrentScale = v.ToString(CultureInfo.InvariantCulture);
82+
}
83+
}
84+
5585
/// <summary>
5686
/// <inheritdoc/>
5787
/// </summary>
@@ -82,6 +112,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
82112
_isFitToPage = Options.IsFitToPage;
83113
_currentPage = Options.CurrentPage;
84114
_url = Options.Url;
115+
_currentScale = Options.CurrentScale;
85116
}
86117

87118
if (_url != Options.Url)
@@ -100,6 +131,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
100131
_currentPage = Options.CurrentPage;
101132
await NavigateToPageAsync(_currentPage);
102133
}
134+
if (_currentScale != Options.CurrentScale)
135+
{
136+
_currentScale = Options.CurrentScale;
137+
await InvokeVoidAsync("scale", Id, _currentScale);
138+
}
103139
}
104140

105141
/// <summary>

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
cursor: pointer;
3232
}
3333

34+
.bb-view-icon.disabled {
35+
color: #6c757d;
36+
}
37+
3438
.bb-view-bar {
3539
margin-inline-end: 2rem;
3640
}

0 commit comments

Comments
 (0)