diff --git a/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj b/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj index b48563d0368..b6df196d4ec 100644 --- a/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj +++ b/src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj @@ -58,6 +58,7 @@ + diff --git a/src/BootstrapBlazor.Server/Components/Samples/PdfViewers.razor b/src/BootstrapBlazor.Server/Components/Samples/PdfViewers.razor new file mode 100644 index 00000000000..62e6dc9327c --- /dev/null +++ b/src/BootstrapBlazor.Server/Components/Samples/PdfViewers.razor @@ -0,0 +1,12 @@ +@page "/pdf-viewer" +@inject IStringLocalizer Localizer + +

@Localizer["PdfViewerTitle"]

+ +

@Localizer["PdfViewerDescription"]

+ + + + + + diff --git a/src/BootstrapBlazor.Server/Components/Samples/PdfViewers.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/PdfViewers.razor.cs new file mode 100644 index 00000000000..46ab8a6b4f3 --- /dev/null +++ b/src/BootstrapBlazor.Server/Components/Samples/PdfViewers.razor.cs @@ -0,0 +1,268 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License +// See the LICENSE file in the project root for more information. +// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone + +using System.ComponentModel; + +namespace BootstrapBlazor.Server.Components.Samples; + +/// +/// PdfViewers +/// +public partial class PdfViewers +{ + [NotNull] + PdfReader? AdvancedPdfReader { get; set; } + + [DisplayName("流模式")] + private bool StreamMode { get; set; } + + [DisplayName("禁用复制/打印/下载")] + private bool ReadOnly { get; set; } + + [DisplayName("水印内容")] + private string Watermark { get; set; } = "www.blazor.zone"; + + private EnumZoomMode Zoom { get; set; } = EnumZoomMode.PageHeight; + + private EnumPageMode PageMode { get; set; } = EnumPageMode.None; + + [DisplayName("搜索")] + private string? Search { get; set; } = "Performance"; + + private int Page { get; set; } = 3; + + private async Task ApplyZoom() + { + Zoom = Zoom switch + { + EnumZoomMode.Auto => EnumZoomMode.PageActual, + EnumZoomMode.PageActual => EnumZoomMode.PageFit, + EnumZoomMode.PageFit => EnumZoomMode.PageWidth, + EnumZoomMode.PageWidth => EnumZoomMode.PageHeight, + EnumZoomMode.PageHeight => EnumZoomMode.Zoom75, + EnumZoomMode.Zoom75 => EnumZoomMode.Zoom50, + EnumZoomMode.Zoom50 => EnumZoomMode.Zoom25, + EnumZoomMode.Zoom25 => EnumZoomMode.Zoom200, + _ => EnumZoomMode.Auto + }; + await Refresh(); + } + + private async Task ApplyPageMode() + { + PageMode = PageMode switch + { + EnumPageMode.Thumbs => EnumPageMode.Outline, + EnumPageMode.Outline => EnumPageMode.Attachments, + EnumPageMode.Attachments => EnumPageMode.Layers, + EnumPageMode.Layers => EnumPageMode.None, + _ => EnumPageMode.Thumbs + }; + await Refresh(); + } + + async Task Refresh() + { + if (AdvancedPdfReader != null) + await AdvancedPdfReader.Refresh(Search, Page, PageMode, Zoom, ReadOnly, Watermark); + } + + private async Task ApplyPage() + { + Search = null; + await Refresh(); + } + + private async Task ApplyPagePrevious() + { + Page--; + Search = null; + await Refresh(); + } + + private async Task ApplyPageNext() + { + Page++; + Search = null; + await Refresh(); + } + + private Task ApplySearch() => Refresh(); + + private Task Clear() + { + Search = string.Empty; + StateHasChanged(); + return Task.CompletedTask; + } + + /// + /// GetAttributes + /// + /// + protected AttributeItem[] GetAttributes() => + [ + new() + { + Name = "Filename", + Description = Localizer["AttributesPdfReaderFilename"], + Type = "string?", + ValueList = "-", + DefaultValue = "-" + }, + new() + { + Name = "StreamMode", + Description = Localizer["AttributesPdfReaderStreamMode"], + Type = "bool", + ValueList = "-", + DefaultValue = "false" + }, + new() + { + Name = "Width", + Description = Localizer["AttributesPdfReaderWidth"], + Type = "string", + ValueList = "-", + DefaultValue = "100%" + }, + new() + { + Name = "Height", + Description = Localizer["AttributesPdfReaderHeight"], + Type = "string", + ValueList = "-", + DefaultValue = "700px" + }, + new() + { + Name = "StyleString", + Description = Localizer["AttributesPdfReaderStyleString"], + Type = "string", + ValueList = "-", + DefaultValue = "-" + }, + new() + { + Name = "Page", + Description = Localizer["AttributesPdfReaderPage"], + Type = "int", + ValueList = "-", + DefaultValue = "1" + }, + new() + { + Name = "PageMode", + Description = Localizer["AttributesPdfReaderPageMode"], + Type = "EnumPageMode", + ValueList = "-", + DefaultValue = "Thumbs" + }, + new() + { + Name = "Zoom", + Description = Localizer["AttributesPdfReaderZoom"], + Type = "EnumZoomMode", + ValueList = "-", + DefaultValue = "Auto" + }, + new() + { + Name = "Search", + Description = Localizer["AttributesPdfReaderSearch"], + Type = "string?", + ValueList = "-", + DefaultValue = "-" + }, + new() + { + Name = "Refresh()", + Description = Localizer["AttributesPdfReaderRefresh"], + Type = "Task", + ValueList = "-", + DefaultValue = "-" + }, + new() + { + Name = "NavigateToPage(int page)", + Description = Localizer["AttributesPdfReaderNavigateToPage"], + Type = "Task", + ValueList = "-", + DefaultValue = "-" + }, + new() + { + Name = "Refresh(int page)", + Description = Localizer["AttributesPdfReaderRefreshPage"], + Type = "Task", + ValueList = "-", + DefaultValue = "-" + }, + new() + { + Name = "Refresh(string? search, int? page, EnumPageMode? pageMode, EnumZoomMode? zoom)", + Description = Localizer["AttributesPdfReaderRefreshComponent"], + Type = "Task", + ValueList = "-", + DefaultValue = "-" + }, + new() + { + Name = "Stream", + Description = Localizer["AttributesPdfReaderStream"], + Type = "Stream?", + ValueList = "-", + DefaultValue = "-" + }, + new() + { + Name = "ViewerBase", + Description = Localizer["AttributesPdfReaderViewerBase"], + Type = "string", + ValueList = "-", + DefaultValue = Localizer["AttributesPdfReaderViewerBaseDefaultValue"], + }, + new() + { + Name = "NavPanels", + Description = Localizer["AttributesPdfReaderNavPanels"], + Type = "bool", + ValueList = "-", + DefaultValue = "true" + }, + new() + { + Name = "Toolbar", + Description = Localizer["AttributesPdfReaderToolbar"], + Type = "bool", + ValueList = "-", + DefaultValue = "true" + }, + new() + { + Name = "StatusBar", + Description = Localizer["AttributesPdfReaderStatusBar"], + Type = "bool", + ValueList = "-", + DefaultValue = "true" + }, + new() + { + Name = "Debug", + Description = Localizer["AttributesPdfReaderDebug"], + Type = "bool", + ValueList = "-", + DefaultValue = "false" + }, + new() + { + Name = nameof(PdfReader.LocalFileName), + Description = Localizer[nameof(PdfReader.LocalFileName)], + Type = "string", + ValueList = " — ", + DefaultValue = " — " + } + ]; +} diff --git a/src/BootstrapBlazor.Server/Extensions/MenusLocalizerExtensions.cs b/src/BootstrapBlazor.Server/Extensions/MenusLocalizerExtensions.cs index 80ea5a633d3..54f284ce7d1 100644 --- a/src/BootstrapBlazor.Server/Extensions/MenusLocalizerExtensions.cs +++ b/src/BootstrapBlazor.Server/Extensions/MenusLocalizerExtensions.cs @@ -706,6 +706,12 @@ void AddData(DemoMenuItem item) Url = "pdf-reader" }, new() + { + IsNew = true, + Text = Localizer["PdfViewer"], + Url = "pdf-viewer" + }, + new() { Text = Localizer["Player"], Url = "player" diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json index ff88e9dae37..d1a7503a59d 100644 --- a/src/BootstrapBlazor.Server/Locales/en-US.json +++ b/src/BootstrapBlazor.Server/Locales/en-US.json @@ -4856,6 +4856,7 @@ "PulseButton": "PulseButton", "Bluetooth": "IBluetooth", "PdfReader": "PDF Reader", + "PdfViewer": "PDF Viewer", "VideoPlayer": "VideoPlayer", "FileViewer": "FileViewer", "FlipClock": "FlipClock", @@ -6156,6 +6157,12 @@ "PdfReaderCompatibilityModeTips": "- Chrome < 97 automatically uses version 2.4.456
- Chrome < 109 automatically uses version 2.6.347
- Note: ReadOnly and Watermark cannot be used in these two compatibility modes", "LocalFileName": "local PDF file path" }, + "BootstrapBlazor.Server.Components.Samples.PdfViewers": { + "PdfViewerTitle": "PDFViewer", + "PdfViewerDescription": "Open the PDF file in the component to read its contents", + "PdfViewerNormalTitle": "Basic usage", + "PdfViewerNormalIntro": "Load a PDF file by setting the Url parameter" + }, "BootstrapBlazor.Server.Components.Samples.VideoPlayers": { "VideoPlayersTitle": "VideoPlayer", "VideoPlayersNormalTitle": "Basic usage", diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json index 211bd6fdbc7..ddfd7c4f8bb 100644 --- a/src/BootstrapBlazor.Server/Locales/zh-CN.json +++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json @@ -4856,6 +4856,7 @@ "PulseButton": "心跳按钮 PulseButton", "Bluetooth": "蓝牙服务 IBluetoothService", "PdfReader": "PDF阅读器 PDF Reader", + "PdfViewer": "PDF阅读器 PDF Viewer", "VideoPlayer": "视频播放器 VideoPlayer", "FileViewer": "文件预览器 FileViewer", "FlipClock": "卡片翻转时钟 FlipClock", @@ -6156,6 +6157,12 @@ "PdfReaderCompatibilityModeTips": "- Chrome < 97 自动使用 2.4.456 版本
- Chrome < 109 自动使用 2.6.347 版本
- 注:ReadOnly 和 Watermark 在这两种兼容模式下不能使用", "LocalFileName": "PDF本地文件路径" }, + "BootstrapBlazor.Server.Components.Samples.PdfViewers": { + "PdfViewerTitle": "PDFViewer PDF 阅读器", + "PdfViewerDescription": "在组件中打开 Pdf 文件阅读其内容", + "PdfViewerNormalTitle": "基础用法", + "PdfViewerNormalIntro": "通过设置 Url 参数加载 Pdf 文件" + }, "BootstrapBlazor.Server.Components.Samples.VideoPlayers": { "VideoPlayersTitle": "VideoPlayer 视频播放器", "VideoPlayersNormalTitle": "基础用法", diff --git a/src/BootstrapBlazor.Server/docs.json b/src/BootstrapBlazor.Server/docs.json index 624bc52b36b..183ef5c10ae 100644 --- a/src/BootstrapBlazor.Server/docs.json +++ b/src/BootstrapBlazor.Server/docs.json @@ -123,6 +123,7 @@ "onscreen-keyboard": "OnScreenKeyboards", "pagination": "Paginations", "pdf-reader": "PdfReaders", + "pdf-viewer": "PdfViewers", "pop-confirm": "PopoverConfirms", "popover": "Popovers", "progress": "Progress", diff --git a/src/BootstrapBlazor.Server/wwwroot/samples/pdf-viewer.pdf b/src/BootstrapBlazor.Server/wwwroot/samples/pdf-viewer.pdf new file mode 100644 index 00000000000..65570184ac8 Binary files /dev/null and b/src/BootstrapBlazor.Server/wwwroot/samples/pdf-viewer.pdf differ