Skip to content

feat(PdfReader): add rotate function#713

Merged
ArgoZhang merged 4 commits intomasterfrom
dev-pdf
Nov 24, 2025
Merged

feat(PdfReader): add rotate function#713
ArgoZhang merged 4 commits intomasterfrom
dev-pdf

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Nov 24, 2025

Link issues

fixes #712

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add bidirectional page rotation controls to the PdfReader component and wire them to a new client-side rotation implementation.

New Features:

  • Expose RotateLeft and RotateRight actions on the PdfReader toolbar to rotate the current PDF view in 90-degree steps.

Enhancements:

  • Replace the previous element-based rotation logic with a viewer-level pagesRotation-based implementation in the PdfReader JavaScript.

Copilot AI review requested due to automatic review settings November 24, 2025 08:56
@bb-auto bb-auto Bot added the enhancement New feature or request label Nov 24, 2025
@bb-auto bb-auto Bot added this to the v9.2.0 milestone Nov 24, 2025
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Nov 24, 2025

Reviewer's Guide

Adds client- and server-side support for rotating PDF pages in the PdfReader component, wiring new toolbar buttons to a JavaScript rotation function and deprecating the old rotation path via pdf.js.

Sequence diagram for new PDF rotation interactions in PdfReader

sequenceDiagram
    actor "User"
    participant "PdfReader (Razor Component)"
    participant "Blazor JSRuntime"
    participant "PdfReader.razor.js"
    participant "pdfViewer (pdf.js viewer instance)"

    "User" ->> "PdfReader (Razor Component)": "Click rotate-left toolbar button"
    "PdfReader (Razor Component)" ->> "Blazor JSRuntime": "InvokeVoidAsync(\"rotate\", Id, -90)"
    "Blazor JSRuntime" ->> "PdfReader.razor.js": "Call rotate(id, -90)"
    "PdfReader.razor.js" ->> "pdfViewer (pdf.js viewer instance)": "Lookup via Data.get(id)"
    "PdfReader.razor.js" ->> "pdfViewer (pdf.js viewer instance)": "Update pagesRotation with offset -90 (mod 360)"

    "User" ->> "PdfReader (Razor Component)": "Click rotate-right toolbar button"
    "PdfReader (Razor Component)" ->> "Blazor JSRuntime": "InvokeVoidAsync(\"rotate\", Id, 90)"
    "Blazor JSRuntime" ->> "PdfReader.razor.js": "Call rotate(id, 90)"
    "PdfReader.razor.js" ->> "pdfViewer (pdf.js viewer instance)": "Lookup via Data.get(id)"
    "PdfReader.razor.js" ->> "pdfViewer (pdf.js viewer instance)": "Update pagesRotation with offset 90 (mod 360)"
Loading

File-Level Changes

Change Details Files
Introduce a new JavaScript-side rotate helper that adjusts pdf.js viewer pagesRotation based on an offset.
  • Add rotate(id, offset) export that looks up the pdfViewer from Data, adjusts pagesRotation by the given offset, and normalizes it using modulo 360.
  • Use a default starting rotation value when pagesRotation is not yet set to ensure rotation always has a base value.
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js
Deprecate the old rotation implementation that directly manipulated a pdf object’s rotation and re-rendered a page.
  • Comment out the previous rotate(invoke, elementId, rotation) function that validated a fixed rotation value and set pdf.rotation followed by queueRenderPage.
  • Retain the function in comments for reference but stop using it in favor of the new viewer-based rotation mechanism.
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js
Expose rotation actions from the PdfReader Razor component and bind them to toolbar buttons.
  • Add RotateLeft and RotateRight async methods that invoke the JavaScript rotate function with -90 and +90 degree offsets respectively, using the component’s Id.
  • Wire the existing left-rotation toolbar icon to call RotateLeft on click, and introduce a new right-rotation toolbar icon that calls RotateRight.
  • Keep existing fit-to-page and fit-to-width behavior unchanged while extending the toolbar with rotation controls.
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs
src/components/BootstrapBlazor.PdfReader/PdfReader.razor

Assessment against linked issues

Issue Objective Addressed Explanation
#712 Add a rotate function to the PdfReader component that allows rotating the displayed PDF pages (e.g., via UI controls and corresponding JS interop).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • In PdfReader.razor.js, the rotation baseline let rotate = pdfViewer.pagesRotation || 360; will treat an existing 0° rotation as falsy and reset to 360°; consider using a null/undefined check (e.g., ?? 0) so 0 remains a valid rotation state.
  • It may be worth validating the offset parameter in the new rotate JS function (e.g., ensuring it is a multiple of 90) to avoid ending up with non-standard rotation angles if the API is misused.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In PdfReader.razor.js, the rotation baseline `let rotate = pdfViewer.pagesRotation || 360;` will treat an existing 0° rotation as falsy and reset to 360°; consider using a null/undefined check (e.g., `?? 0`) so 0 remains a valid rotation state.
- It may be worth validating the `offset` parameter in the new `rotate` JS function (e.g., ensuring it is a multiple of 90) to avoid ending up with non-standard rotation angles if the API is misused.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds page rotation functionality to the PdfReader component, allowing users to rotate PDF pages left and right by 90-degree increments. The implementation replaces an older, unused rotation function with a new approach that leverages the pdf.js viewer's built-in pagesRotation property.

Key Changes

  • Added RotateLeft() and RotateRight() public methods in C# that rotate pages by -90° and +90° respectively
  • Implemented a new rotate(id, offset) JavaScript function that manipulates the pagesRotation property of the PDFViewer
  • Added UI buttons in the toolbar for both rotation directions with Font Awesome icons

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
PdfReader.razor.js Added new rotate() function using pdf.js viewer API; commented out old rotation implementation
PdfReader.razor.cs Added RotateLeft() and RotateRight() public async methods with version bump
PdfReader.razor Added two rotation button elements to toolbar with click handlers
BootstrapBlazor.PdfReader.csproj Updated version to 10.0.1-beta01; includes commented PackageReference

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js
Comment thread src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs
Comment thread src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs
@ArgoZhang ArgoZhang merged commit 034634a into master Nov 24, 2025
2 checks passed
@ArgoZhang ArgoZhang deleted the dev-pdf branch November 24, 2025 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(PdfReader): add rotate function

2 participants