Skip to content

Commit 034634a

Browse files
authored
feat(PdfReader): add rotate function (#713)
* chore: 更新工程依赖 * feat(PdfReader): add Rotate function * feat: 增加旋转按钮功能 * refactor: 更改变量名称
1 parent 8292a92 commit 034634a

4 files changed

Lines changed: 41 additions & 10 deletions

File tree

src/components/BootstrapBlazor.PdfReader/BootstrapBlazor.PdfReader.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

3+
<PropertyGroup>
4+
<Version>10.0.1-beta01</Version>
5+
</PropertyGroup>
6+
37
<PropertyGroup>
48
<PackageTags>Bootstrap Blazor WebAssembly wasm UI Components Pdf Reader</PackageTags>
59
<Description>Bootstrap UI components extensions of PdfReader</Description>
@@ -14,6 +18,7 @@
1418

1519
<ItemGroup>
1620
<ProjectReference Include="..\..\..\..\BootstrapBlazor\src\BootstrapBlazor\BootstrapBlazor.csproj" />
21+
<!--<PackageReference Include="BootstrapBlazor" Version="$(BBVersion)" />-->
1722
</ItemGroup>
1823

1924
<ItemGroup>

src/components/BootstrapBlazor.PdfReader/PdfReader.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
<div class="bb-view-divider"></div>
1818
<div class="bb-view-icon bb-view-fit-page" @onclick="FitToPage"><i class="fa-solid fa-arrows-left-right-to-line"></i></div>
1919
<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-rotate"><i class="fa-solid fa-rotate-left"></i></div>
20+
<div class="bb-view-icon bb-view-fit-rotate" @onclick="RotateLeft"><i class="fa-solid fa-rotate-left"></i></div>
21+
<div class="bb-view-icon bb-view-fit-rotate" @onclick="RotateRight"><i class="fa-solid fa-rotate-right"></i></div>
2122
<div class="bb-view-divider"></div>
2223
<div class="bb-view-icon bb-view-draw"><i class="fa-solid fa-pen-to-square"></i></div>
2324
</div>

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,31 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
9393
/// <summary>
9494
/// 适应页面宽度
9595
/// </summary>
96-
/// <returns></returns>
9796
public void FitToPage() => IsFitToPage = true;
9897

9998
/// <summary>
10099
/// 适应文档宽度
101100
/// </summary>
102-
/// <returns></returns>
103101
public void FitToWidth() => IsFitToPage = false;
104102

103+
/// <summary>
104+
/// 旋转页面方法
105+
/// </summary>
106+
/// <returns></returns>
107+
public async Task RotateLeft()
108+
{
109+
await InvokeVoidAsync("rotate", Id, -90);
110+
}
111+
112+
/// <summary>
113+
/// 旋转页面方法
114+
/// </summary>
115+
/// <returns></returns>
116+
public async Task RotateRight()
117+
{
118+
await InvokeVoidAsync("rotate", Id, 90);
119+
}
120+
105121
private Task TriggerFit(string methodName) => InvokeVoidAsync(methodName, Id);
106122

107123
/// <summary>

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ export function fitToPage(id) {
9393
}
9494
}
9595

96+
export function rotate(id, step) {
97+
const pdfViewer = Data.get(id);
98+
if (pdfViewer) {
99+
let rotate = pdfViewer.pagesRotation || 360;
100+
rotate += step;
101+
pdfViewer.pagesRotation = rotate % 360;
102+
}
103+
}
104+
96105
export function dispose(id) {
97106
Data.get(id);
98107
}
@@ -252,16 +261,16 @@ export async function print(invoke, elementId, url) {
252261
1000);
253262
}
254263

255-
export function rotate(invoke, elementId, rotation) {
256-
const pdf = getPdf(elementId);
264+
//export function rotate(invoke, elementId, rotation) {
265+
// const pdf = getPdf(elementId);
257266

258-
if (pdf == null || Number.isNaN(rotation) || rotation % 90 !== 0)
259-
return;
267+
// if (pdf == null || Number.isNaN(rotation) || rotation % 90 !== 0)
268+
// return;
260269

261-
pdf.rotation = rotation;
270+
// pdf.rotation = rotation;
262271

263-
queueRenderPage(pdf, pdf.pageNum);
264-
}
272+
// queueRenderPage(pdf, pdf.pageNum);
273+
//}
265274

266275
export function zoomInOut(invoke, elementId, scale) {
267276
const pdf = getPdf(elementId);

0 commit comments

Comments
 (0)