Skip to content

Commit 62c78b6

Browse files
committed
feat(PdfReader): add Rotate function
1 parent 9c28dd6 commit 62c78b6

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

src/components/BootstrapBlazor.PdfReader/PdfReader.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
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="Rotate"><i class="fa-solid fa-rotate-left"></i></div>
2121
<div class="bb-view-divider"></div>
2222
<div class="bb-view-icon bb-view-draw"><i class="fa-solid fa-pen-to-square"></i></div>
2323
</div>

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

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

9998
/// <summary>
10099
/// 适应文档宽度
101100
/// </summary>
102-
/// <returns></returns>
103-
public void FitToWidth() => IsFitToPage = false;
101+
private void FitToWidth() => IsFitToPage = false;
102+
103+
public async Task Rotate()
104+
{
105+
await InvokeVoidAsync("rotate", Id);
106+
}
104107

105108
private Task TriggerFit(string methodName) => InvokeVoidAsync(methodName, Id);
106109

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) {
97+
const pdfViewer = Data.get(id);
98+
if (pdfViewer) {
99+
let rotate = pdfViewer.pagesRotation || 360;
100+
rotate -= 90;
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)