Skip to content

feat(PdfReader): add SetFitMode function#754

Merged
ArgoZhang merged 3 commits intomasterfrom
dev-fit
Nov 29, 2025
Merged

feat(PdfReader): add SetFitMode function#754
ArgoZhang merged 3 commits intomasterfrom
dev-fit

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

Link issues

fixes #753

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

Copilot AI review requested due to automatic review settings November 29, 2025 05:13
@bb-auto bb-auto Bot added the enhancement New feature or request label Nov 29, 2025
@bb-auto bb-auto Bot added this to the v9.2.0 milestone Nov 29, 2025
@ArgoZhang ArgoZhang merged commit 23534ba into master Nov 29, 2025
3 checks passed
@ArgoZhang ArgoZhang deleted the dev-fit branch November 29, 2025 05:13
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Nov 29, 2025

Reviewer's Guide

Implements a configurable PDF viewer fit mode that reacts to parameter changes and localizes document properties labels in the PdfReader dialog, including initializing and tracking fit mode state across renders and updating locale resources.

Sequence diagram for updating PDF fit mode on parameter change

sequenceDiagram
    actor User
    participant ParentComponent
    participant BlazorRenderer
    participant PdfReader
    participant JsRuntime

    User->>ParentComponent: Interact to change fit mode
    ParentComponent->>BlazorRenderer: Render PdfReader with new FitMode parameter
    BlazorRenderer->>PdfReader: SetParametersAsync with FitMode
    BlazorRenderer->>PdfReader: OnAfterRenderAsync(firstRender = false)
    PdfReader->>PdfReader: Detect FitMode change (_fitMode != FitMode)
    PdfReader->>PdfReader: Update _fitMode from FitMode
    PdfReader->>PdfReader: SetFitMode(_fitMode)
    PdfReader->>JsRuntime: InvokeVoidAsync setFitMode(id, _fitMode)
    JsRuntime-->>PdfReader: Apply new fit mode in viewer
    PdfReader-->>User: Updated PDF display according to new fit mode
Loading

Class diagram for PdfReader fit mode implementation

classDiagram
    class PdfReader {
        - string url
        - string id
        - bool enableThumbnails
        - bool showToolbar
        - PdfReaderFitMode fitMode
        - string dropdownItemDefaultIcon
        - int currentPage
        + PdfReader()
        + PdfReaderFitMode FitMode
        + bool EnableThumbnails
        + bool ShowToolbar
        + int CurrentPage
        + string Url
        + Task OnAfterRenderAsync(bool firstRender)
        + Task SetFitMode(PdfReaderFitMode fitMode)
    }

    class PdfReaderFitMode {
        <<enumeration>>
        PageActual
        PageWidth
        PageHeight
    }

    PdfReader --> PdfReaderFitMode : uses
Loading

File-Level Changes

Change Details Files
Make document properties dialog fully localizable and adjust default field placeholders.
  • Replace hard-coded English labels in the document properties dialog with Localizer resource lookups for each field label.
  • Set default placeholder text ("-") for metadata values that may be empty instead of leaving content blank.
  • Keep existing structure of the dialog and CSS classes while only changing text and defaults.
src/components/BootstrapBlazor.PdfReader/PdfReader.razor
src/components/BootstrapBlazor.PdfReader/Locales/en.json
src/components/BootstrapBlazor.PdfReader/Locales/zh.json
Refine PdfReader fit mode options and introduce reactive fit-mode handling in the component lifecycle.
  • Reorder and trim PdfReaderFitMode enum values so that only PageActual, PageWidth, and PageHeight remain, with updated Description attributes to match the underlying viewer values.
  • Add a backing field for the FitMode parameter in PdfReader to track previous fit mode across renders.
  • Initialize the backing fit mode field during first render from the FitMode parameter and detect subsequent parameter changes in OnAfterRenderAsync.
  • Invoke a new SetFitMode method when the FitMode parameter changes, passing the updated enum value so the underlying viewer can apply the new fit mode dynamically.
src/components/BootstrapBlazor.PdfReader/PdfReaderFitMode.cs
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs

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 and found some issues that need to be addressed.

  • Removing PageFit and Auto from PdfReaderFitMode (and changing the enum shape) is a breaking change for consumers; consider either keeping the old values (even if unused) or introducing a non-breaking migration path.
  • In OnAfterRenderAsync, the initial FitMode is stored during firstRender but SetFitMode is only called when _fitMode != FitMode, so the initial fit mode may never be applied; consider invoking SetFitMode on first render as well.
  • The dialog now localizes labels but keeps hardcoded values like "No" and "-"; consider localizing these values or using resource-based placeholders for consistency across languages.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Removing `PageFit` and `Auto` from `PdfReaderFitMode` (and changing the enum shape) is a breaking change for consumers; consider either keeping the old values (even if unused) or introducing a non-breaking migration path.
- In `OnAfterRenderAsync`, the initial `FitMode` is stored during `firstRender` but `SetFitMode` is only called when `_fitMode != FitMode`, so the initial fit mode may never be applied; consider invoking `SetFitMode` on first render as well.
- The dialog now localizes labels but keeps hardcoded values like "No" and "-"; consider localizing these values or using resource-based placeholders for consistency across languages.

## Individual Comments

### Comment 1
<location> `src/components/BootstrapBlazor.PdfReader/PdfReaderFitMode.cs:12-16` </location>
<code_context>
 /// </summary>
 public enum PdfReaderFitMode
 {
-    /// <summary>
</code_context>

<issue_to_address>
**issue (bug_risk):** Enum reordering removes members and changes underlying values, which may break persisted or serialized values.

The original enum implicitly used values 0–4 for `PageWidth`, `PageActual`, `PageHeight`, `PageFit`, and `Auto`. The new version both removes `PageFit`/`Auto` and reorders the remaining members, so their underlying integer values change. If these values are stored (DB, URLs, local storage) or cross process boundaries (JS interop, config, etc.), this becomes a silent breaking change on upgrade.

To avoid that, keep the original numeric mapping with explicit values, and reserve the removed ones, e.g.:

```csharp
public enum PdfReaderFitMode
{
    [Description("page-width")]
    PageWidth = 0,

    [Description("page-actual")]
    PageActual = 1,

    [Description("page-height")]
    PageHeight = 2,

    // PageFit = 3,
    // Auto = 4,
}
```

This preserves compatibility while hiding the removed options from the public API.
</issue_to_address>

### Comment 2
<location> `src/components/BootstrapBlazor.PdfReader/PdfReader.razor:167-168` </location>
<code_context>
             </div>
             <div class="bb-view-pdf-dialog-item">
-                <div class="bb-view-pdf-dialog-label">Fast web view:</div>
+                <div class="bb-view-pdf-dialog-label">@Localizer["DocumentFastWebView"]</div>
                 <div class="bb-view-pdf-dialog-webview">No</div>
             </div>
             <div class="bb-view-pdf-dialog-close">
</code_context>

<issue_to_address>
**suggestion:** The 'No' literal for Fast Web View is not localized, unlike the surrounding labels.

The label is now localized via `Localizer[...]`, but the Fast Web View value is still hard-coded as `"No"`, which breaks localization consistency and affects non-English users.

Please localize this value as well (e.g. `@Localizer["DocumentFastWebViewDisabled"]` or a shared localized `Yes`/`No`), and ensure all possible values for this field are localized if it can be dynamic in the future.

Suggested implementation:

```
            <div class="bb-view-pdf-dialog-item">
                <div class="bb-view-pdf-dialog-label">@Localizer["DocumentFastWebView"]</div>
                <div class="bb-view-pdf-dialog-webview">@Localizer["DocumentFastWebViewDisabled"]</div>
            </div>

```

1. Add a `"DocumentFastWebViewDisabled"` entry to the relevant `.resx`/localization resources for all supported languages.
2. If this Fast Web View value becomes dynamic (e.g. Yes/No) in the future, ensure any other states (like `"DocumentFastWebViewEnabled"`) are also localized using the same `Localizer[...]` pattern.
</issue_to_address>

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 dynamic FitMode switching capability to the PdfReader component and improves localization of document properties. The main purpose is to enable runtime changes to the PDF viewer's fit mode (PageActual, PageWidth, PageHeight) by implementing change detection and a SetFitMode method. Additionally, it localizes hardcoded English strings in the document properties dialog.

Key Changes:

  • Added dynamic FitMode parameter change detection in OnAfterRenderAsync to call SetFitMode when the property changes
  • Reorganized PdfReaderFitMode enum by removing PageFit and Auto values and reordering remaining values
  • Converted hardcoded English text in document properties dialog to use localized strings via @localizer syntax

Reviewed changes

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

Show a summary per file
File Description
PdfReaderFitMode.cs Simplified enum by removing PageFit and Auto values, reordered remaining values
PdfReader.razor.cs Added _fitMode field and change detection logic to support dynamic FitMode updates
PdfReader.razor Replaced hardcoded English strings with localized @localizer keys and added default "-" values
zh.json Added Chinese translations for document properties fields
en.json Added English translations for document properties fields
BootstrapBlazor.PdfReader.csproj Version bump from 10.0.7 to 10.0.8

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

"DocumentVersion": "PDF 版本:",
"DocumentPageCount": "页数:",
"DocumentPageSize": "页面尺寸:",
"DocumentFastWebView": "Fast web view:"
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

The 'DocumentFastWebView' localization value in the Chinese (zh.json) file is not translated and remains in English. It should be translated to Chinese for consistency. Consider translating to something like '快速网页浏览:' or '快速 Web 视图:' to match the localization pattern used for other fields.

Suggested change
"DocumentFastWebView": "Fast web view:"
"DocumentFastWebView": "快速网页浏览:"

Copilot uses AI. Check for mistakes.
"DocumentProperty": "Document properties",
"CloseButtonText": "Close"
"CloseButtonText": "Close",
"DocumentProperties": "Document properties",
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

The key 'DocumentProperties' has the same value as the existing 'DocumentProperty' key (line 15). This creates duplicate localization entries with identical values. Consider removing the duplicate 'DocumentProperties' entry and using 'DocumentProperty' consistently, or clarify if they serve different purposes.

Suggested change
"DocumentProperties": "Document properties",

Copilot uses AI. Check for mistakes.
"DocumentProperty": "文档属性",
"CloseButtonText": "关闭"
"CloseButtonText": "关闭",
"DocumentProperties": "文档属性",
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

The key 'DocumentProperties' has the same value as the existing 'DocumentProperty' key (line 15). This creates duplicate localization entries with identical values. Consider removing the duplicate 'DocumentProperties' entry and using 'DocumentProperty' consistently, or clarify if they serve different purposes.

Suggested change
"DocumentProperties": "文档属性",

Copilot uses AI. Check for mistakes.
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 SetFitMode function

2 participants