WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>10.0.10</Version>
<Version>10.0.11</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/components/BootstrapBlazor.PdfReader/PdfReader.razor
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<div class="bb-view-group bb-view-controls invisible">
@if (ShowDownload)
{
<div class="bb-view-icon bb-view-download" title="@Localizer["Download"]" @onclick="OnDownload"><i class="fa-solid fa-fw fa-arrow-right-to-bracket fa-rotate-90"></i></div>
<div class="bb-view-icon bb-view-download" title="@Localizer["Download"]"><i class="fa-solid fa-fw fa-arrow-right-to-bracket fa-rotate-90"></i></div>
}
@if (ShowPrint)
{
Expand Down
14 changes: 0 additions & 14 deletions src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ public partial class PdfReader
[Parameter]
public string? MoreButtonIcon { get; set; }
Comment on lines 121 to 122
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

Removing the OnDownloadAsync parameter is a breaking API change that will affect existing consumers of this component. Users who were relying on this callback to implement custom download logic (e.g., logging, authentication checks, custom file sources) will no longer be able to do so.

Consider:

  1. Deprecating this parameter instead of removing it immediately, marking it as [Obsolete] in this version
  2. Supporting both the new client-side download and the callback-based approach, allowing the callback to override the default behavior
  3. Documenting this as a breaking change in the release notes

If this breaking change is intentional, ensure it's clearly documented in the changelog and migration guide.

Copilot uses AI. Check for mistakes.

/// <summary>
/// 点击下载按钮回调方法 默认 null
/// </summary>
[Parameter]
public Func<Task>? OnDownloadAsync { get; set; }

/// <summary>
/// 正在打印回调方法 默认 null
/// </summary>
Expand Down Expand Up @@ -272,14 +266,6 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
/// <returns></returns>
public Task RotateRight() => InvokeVoidAsync("rotate", Id, 90);

private async Task OnDownload()
{
if (OnDownloadAsync != null)
{
await OnDownloadAsync();
}
}

/// <summary>
/// 页面开始初始化时回调方法
/// </summary>
Expand Down
13 changes: 11 additions & 2 deletions src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ const loadPdf = async (el, invoke, options) => {
}

const loadMetadata = (el, pdfViewer, metadata) => {
console.log(metadata);

const filename = el.querySelector('.bb-view-pdf-dialog-filename');
const docTitle = el.querySelector('.bb-view-subject');
filename.textContent = docTitle.textContent;
Expand Down Expand Up @@ -439,6 +437,17 @@ const addToolbarEventHandlers = (el, pdfViewer, invoke, options) => {
pdfViewer.spreadMode = 0;
}
});
EventHandler.on(toolbar, "click", ".bb-view-download", e => {
if (options.url) {
const docTitle = el.querySelector('.bb-view-subject');
const anchorElement = document.createElement('a');
anchorElement.href = options.url;
anchorElement.download = docTitle.textContent;
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

The docTitle element should be null-checked before accessing its textContent property. If the element doesn't exist, this will throw a runtime error. Consider adding a null check:

const docTitle = el.querySelector('.bb-view-subject');
if (docTitle && docTitle.textContent) {
    anchorElement.download = docTitle.textContent;
}
Suggested change
anchorElement.download = docTitle.textContent;
anchorElement.download = (docTitle && docTitle.textContent) ? docTitle.textContent : '';

Copilot uses AI. Check for mistakes.
anchorElement.click();
anchorElement.remove();
Comment on lines +440 to +447
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

The download implementation using anchor element with download attribute will not work for cross-origin URLs due to CORS restrictions. When the PDF URL is from a different origin, the browser will navigate to the URL instead of downloading it. This is different from the print functionality which uses an iframe. Consider:

  1. Documenting this limitation in the component documentation, or
  2. Implementing a server-side proxy download mechanism similar to how the previous OnDownloadAsync callback allowed, or
  3. Using a fetch + Blob approach for same-origin URLs:
if (options.url) {
    const docTitle = el.querySelector('.bb-view-subject');
    try {
        const response = await fetch(options.url);
        const blob = await response.blob();
        const url = window.URL.createObjectURL(blob);
        const anchorElement = document.createElement('a');
        anchorElement.href = url;
        anchorElement.download = docTitle?.textContent || 'document.pdf';
        anchorElement.click();
        window.URL.revokeObjectURL(url);
        anchorElement.remove();
    } catch (error) {
        // Fallback to direct link for cross-origin URLs
        const anchorElement = document.createElement('a');
        anchorElement.href = options.url;
        anchorElement.download = docTitle?.textContent || 'document.pdf';
        anchorElement.click();
        anchorElement.remove();
    }
}
Suggested change
EventHandler.on(toolbar, "click", ".bb-view-download", e => {
if (options.url) {
const docTitle = el.querySelector('.bb-view-subject');
const anchorElement = document.createElement('a');
anchorElement.href = options.url;
anchorElement.download = docTitle.textContent;
anchorElement.click();
anchorElement.remove();
EventHandler.on(toolbar, "click", ".bb-view-download", async e => {
if (options.url) {
const docTitle = el.querySelector('.bb-view-subject');
try {
const response = await fetch(options.url);
if (!response.ok) throw new Error("Network response was not ok");
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const anchorElement = document.createElement('a');
anchorElement.href = url;
anchorElement.download = docTitle?.textContent || 'document.pdf';
document.body.appendChild(anchorElement);
anchorElement.click();
window.URL.revokeObjectURL(url);
anchorElement.remove();
} catch (error) {
// Fallback to direct link for cross-origin URLs
const anchorElement = document.createElement('a');
anchorElement.href = options.url;
anchorElement.download = docTitle?.textContent || 'document.pdf';
document.body.appendChild(anchorElement);
anchorElement.click();
anchorElement.remove();
}

Copilot uses AI. Check for mistakes.
}
});

EventHandler.on(toolbar, "click", ".dropdown-item-presentation", async e => {
e.delegateTarget.classList.toggle("active");

Expand Down