|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the Apache 2.0 License |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | +// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone |
| 5 | + |
| 6 | +using System.ComponentModel; |
| 7 | + |
| 8 | +namespace BootstrapBlazor.Server.Components.Samples; |
| 9 | + |
| 10 | +/// <summary> |
| 11 | +/// PdfViewers |
| 12 | +/// </summary> |
| 13 | +public partial class PdfViewers |
| 14 | +{ |
| 15 | + [NotNull] |
| 16 | + PdfReader? AdvancedPdfReader { get; set; } |
| 17 | + |
| 18 | + [DisplayName("流模式")] |
| 19 | + private bool StreamMode { get; set; } |
| 20 | + |
| 21 | + [DisplayName("禁用复制/打印/下载")] |
| 22 | + private bool ReadOnly { get; set; } |
| 23 | + |
| 24 | + [DisplayName("水印内容")] |
| 25 | + private string Watermark { get; set; } = "www.blazor.zone"; |
| 26 | + |
| 27 | + private EnumZoomMode Zoom { get; set; } = EnumZoomMode.PageHeight; |
| 28 | + |
| 29 | + private EnumPageMode PageMode { get; set; } = EnumPageMode.None; |
| 30 | + |
| 31 | + [DisplayName("搜索")] |
| 32 | + private string? Search { get; set; } = "Performance"; |
| 33 | + |
| 34 | + private int Page { get; set; } = 3; |
| 35 | + |
| 36 | + private async Task ApplyZoom() |
| 37 | + { |
| 38 | + Zoom = Zoom switch |
| 39 | + { |
| 40 | + EnumZoomMode.Auto => EnumZoomMode.PageActual, |
| 41 | + EnumZoomMode.PageActual => EnumZoomMode.PageFit, |
| 42 | + EnumZoomMode.PageFit => EnumZoomMode.PageWidth, |
| 43 | + EnumZoomMode.PageWidth => EnumZoomMode.PageHeight, |
| 44 | + EnumZoomMode.PageHeight => EnumZoomMode.Zoom75, |
| 45 | + EnumZoomMode.Zoom75 => EnumZoomMode.Zoom50, |
| 46 | + EnumZoomMode.Zoom50 => EnumZoomMode.Zoom25, |
| 47 | + EnumZoomMode.Zoom25 => EnumZoomMode.Zoom200, |
| 48 | + _ => EnumZoomMode.Auto |
| 49 | + }; |
| 50 | + await Refresh(); |
| 51 | + } |
| 52 | + |
| 53 | + private async Task ApplyPageMode() |
| 54 | + { |
| 55 | + PageMode = PageMode switch |
| 56 | + { |
| 57 | + EnumPageMode.Thumbs => EnumPageMode.Outline, |
| 58 | + EnumPageMode.Outline => EnumPageMode.Attachments, |
| 59 | + EnumPageMode.Attachments => EnumPageMode.Layers, |
| 60 | + EnumPageMode.Layers => EnumPageMode.None, |
| 61 | + _ => EnumPageMode.Thumbs |
| 62 | + }; |
| 63 | + await Refresh(); |
| 64 | + } |
| 65 | + |
| 66 | + async Task Refresh() |
| 67 | + { |
| 68 | + if (AdvancedPdfReader != null) |
| 69 | + await AdvancedPdfReader.Refresh(Search, Page, PageMode, Zoom, ReadOnly, Watermark); |
| 70 | + } |
| 71 | + |
| 72 | + private async Task ApplyPage() |
| 73 | + { |
| 74 | + Search = null; |
| 75 | + await Refresh(); |
| 76 | + } |
| 77 | + |
| 78 | + private async Task ApplyPagePrevious() |
| 79 | + { |
| 80 | + Page--; |
| 81 | + Search = null; |
| 82 | + await Refresh(); |
| 83 | + } |
| 84 | + |
| 85 | + private async Task ApplyPageNext() |
| 86 | + { |
| 87 | + Page++; |
| 88 | + Search = null; |
| 89 | + await Refresh(); |
| 90 | + } |
| 91 | + |
| 92 | + private Task ApplySearch() => Refresh(); |
| 93 | + |
| 94 | + private Task Clear() |
| 95 | + { |
| 96 | + Search = string.Empty; |
| 97 | + StateHasChanged(); |
| 98 | + return Task.CompletedTask; |
| 99 | + } |
| 100 | + |
| 101 | + /// <summary> |
| 102 | + /// GetAttributes |
| 103 | + /// </summary> |
| 104 | + /// <returns></returns> |
| 105 | + protected AttributeItem[] GetAttributes() => |
| 106 | + [ |
| 107 | + new() |
| 108 | + { |
| 109 | + Name = "Filename", |
| 110 | + Description = Localizer["AttributesPdfReaderFilename"], |
| 111 | + Type = "string?", |
| 112 | + ValueList = "-", |
| 113 | + DefaultValue = "-" |
| 114 | + }, |
| 115 | + new() |
| 116 | + { |
| 117 | + Name = "StreamMode", |
| 118 | + Description = Localizer["AttributesPdfReaderStreamMode"], |
| 119 | + Type = "bool", |
| 120 | + ValueList = "-", |
| 121 | + DefaultValue = "false" |
| 122 | + }, |
| 123 | + new() |
| 124 | + { |
| 125 | + Name = "Width", |
| 126 | + Description = Localizer["AttributesPdfReaderWidth"], |
| 127 | + Type = "string", |
| 128 | + ValueList = "-", |
| 129 | + DefaultValue = "100%" |
| 130 | + }, |
| 131 | + new() |
| 132 | + { |
| 133 | + Name = "Height", |
| 134 | + Description = Localizer["AttributesPdfReaderHeight"], |
| 135 | + Type = "string", |
| 136 | + ValueList = "-", |
| 137 | + DefaultValue = "700px" |
| 138 | + }, |
| 139 | + new() |
| 140 | + { |
| 141 | + Name = "StyleString", |
| 142 | + Description = Localizer["AttributesPdfReaderStyleString"], |
| 143 | + Type = "string", |
| 144 | + ValueList = "-", |
| 145 | + DefaultValue = "-" |
| 146 | + }, |
| 147 | + new() |
| 148 | + { |
| 149 | + Name = "Page", |
| 150 | + Description = Localizer["AttributesPdfReaderPage"], |
| 151 | + Type = "int", |
| 152 | + ValueList = "-", |
| 153 | + DefaultValue = "1" |
| 154 | + }, |
| 155 | + new() |
| 156 | + { |
| 157 | + Name = "PageMode", |
| 158 | + Description = Localizer["AttributesPdfReaderPageMode"], |
| 159 | + Type = "EnumPageMode", |
| 160 | + ValueList = "-", |
| 161 | + DefaultValue = "Thumbs" |
| 162 | + }, |
| 163 | + new() |
| 164 | + { |
| 165 | + Name = "Zoom", |
| 166 | + Description = Localizer["AttributesPdfReaderZoom"], |
| 167 | + Type = "EnumZoomMode", |
| 168 | + ValueList = "-", |
| 169 | + DefaultValue = "Auto" |
| 170 | + }, |
| 171 | + new() |
| 172 | + { |
| 173 | + Name = "Search", |
| 174 | + Description = Localizer["AttributesPdfReaderSearch"], |
| 175 | + Type = "string?", |
| 176 | + ValueList = "-", |
| 177 | + DefaultValue = "-" |
| 178 | + }, |
| 179 | + new() |
| 180 | + { |
| 181 | + Name = "Refresh()", |
| 182 | + Description = Localizer["AttributesPdfReaderRefresh"], |
| 183 | + Type = "Task", |
| 184 | + ValueList = "-", |
| 185 | + DefaultValue = "-" |
| 186 | + }, |
| 187 | + new() |
| 188 | + { |
| 189 | + Name = "NavigateToPage(int page)", |
| 190 | + Description = Localizer["AttributesPdfReaderNavigateToPage"], |
| 191 | + Type = "Task", |
| 192 | + ValueList = "-", |
| 193 | + DefaultValue = "-" |
| 194 | + }, |
| 195 | + new() |
| 196 | + { |
| 197 | + Name = "Refresh(int page)", |
| 198 | + Description = Localizer["AttributesPdfReaderRefreshPage"], |
| 199 | + Type = "Task", |
| 200 | + ValueList = "-", |
| 201 | + DefaultValue = "-" |
| 202 | + }, |
| 203 | + new() |
| 204 | + { |
| 205 | + Name = "Refresh(string? search, int? page, EnumPageMode? pageMode, EnumZoomMode? zoom)", |
| 206 | + Description = Localizer["AttributesPdfReaderRefreshComponent"], |
| 207 | + Type = "Task", |
| 208 | + ValueList = "-", |
| 209 | + DefaultValue = "-" |
| 210 | + }, |
| 211 | + new() |
| 212 | + { |
| 213 | + Name = "Stream", |
| 214 | + Description = Localizer["AttributesPdfReaderStream"], |
| 215 | + Type = "Stream?", |
| 216 | + ValueList = "-", |
| 217 | + DefaultValue = "-" |
| 218 | + }, |
| 219 | + new() |
| 220 | + { |
| 221 | + Name = "ViewerBase", |
| 222 | + Description = Localizer["AttributesPdfReaderViewerBase"], |
| 223 | + Type = "string", |
| 224 | + ValueList = "-", |
| 225 | + DefaultValue = Localizer["AttributesPdfReaderViewerBaseDefaultValue"], |
| 226 | + }, |
| 227 | + new() |
| 228 | + { |
| 229 | + Name = "NavPanels", |
| 230 | + Description = Localizer["AttributesPdfReaderNavPanels"], |
| 231 | + Type = "bool", |
| 232 | + ValueList = "-", |
| 233 | + DefaultValue = "true" |
| 234 | + }, |
| 235 | + new() |
| 236 | + { |
| 237 | + Name = "Toolbar", |
| 238 | + Description = Localizer["AttributesPdfReaderToolbar"], |
| 239 | + Type = "bool", |
| 240 | + ValueList = "-", |
| 241 | + DefaultValue = "true" |
| 242 | + }, |
| 243 | + new() |
| 244 | + { |
| 245 | + Name = "StatusBar", |
| 246 | + Description = Localizer["AttributesPdfReaderStatusBar"], |
| 247 | + Type = "bool", |
| 248 | + ValueList = "-", |
| 249 | + DefaultValue = "true" |
| 250 | + }, |
| 251 | + new() |
| 252 | + { |
| 253 | + Name = "Debug", |
| 254 | + Description = Localizer["AttributesPdfReaderDebug"], |
| 255 | + Type = "bool", |
| 256 | + ValueList = "-", |
| 257 | + DefaultValue = "false" |
| 258 | + }, |
| 259 | + new() |
| 260 | + { |
| 261 | + Name = nameof(PdfReader.LocalFileName), |
| 262 | + Description = Localizer[nameof(PdfReader.LocalFileName)], |
| 263 | + Type = "string", |
| 264 | + ValueList = " — ", |
| 265 | + DefaultValue = " — " |
| 266 | + } |
| 267 | + ]; |
| 268 | +} |
0 commit comments