Skip to content

Commit 3011026

Browse files
authored
feat(PdfViewer): add PdfViewer component (#6164)
* chore: 增加 PdfViewer 包 * doc: 增加 PdfViewer 示例 * chore: 增加源码映射 * doc: 增加菜单
1 parent 406eb19 commit 3011026

File tree

8 files changed

+302
-0
lines changed

8 files changed

+302
-0
lines changed

src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<PackageReference Include="BootstrapBlazor.OctIcon" Version="9.0.4" />
5959
<PackageReference Include="BootstrapBlazor.OnScreenKeyboard" Version="9.0.1" />
6060
<PackageReference Include="BootstrapBlazor.PdfReader" Version="9.0.1" />
61+
<PackageReference Include="BootstrapBlazor.PdfViewer" Version="9.0.0-beta01" />
6162
<PackageReference Include="BootstrapBlazor.Player" Version="9.0.1" />
6263
<PackageReference Include="BootstrapBlazor.RDKit" Version="9.0.2" />
6364
<PackageReference Include="BootstrapBlazor.SignaturePad" Version="9.0.1" />
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@page "/pdf-viewer"
2+
@inject IStringLocalizer<PdfViewers> Localizer
3+
4+
<h3>@Localizer["PdfViewerTitle"]</h3>
5+
6+
<h4>@Localizer["PdfViewerDescription"]</h4>
7+
8+
<PackageTips Name="BootstrapBlazor.PdfViewer" />
9+
10+
<DemoBlock Title="@Localizer["PdfViewerNormalTitle"]" Introduction="@Localizer["PdfViewerNormalIntro"]" Name="Normal">
11+
<PdfViewer Url="./samples/pdf-viewer.pdf" Height="620px"></PdfViewer>
12+
</DemoBlock>
Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
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+
}

src/BootstrapBlazor.Server/Extensions/MenusLocalizerExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,12 @@ void AddData(DemoMenuItem item)
706706
Url = "pdf-reader"
707707
},
708708
new()
709+
{
710+
IsNew = true,
711+
Text = Localizer["PdfViewer"],
712+
Url = "pdf-viewer"
713+
},
714+
new()
709715
{
710716
Text = Localizer["Player"],
711717
Url = "player"

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4856,6 +4856,7 @@
48564856
"PulseButton": "PulseButton",
48574857
"Bluetooth": "IBluetooth",
48584858
"PdfReader": "PDF Reader",
4859+
"PdfViewer": "PDF Viewer",
48594860
"VideoPlayer": "VideoPlayer",
48604861
"FileViewer": "FileViewer",
48614862
"FlipClock": "FlipClock",
@@ -6156,6 +6157,12 @@
61566157
"PdfReaderCompatibilityModeTips": "- Chrome < 97 automatically uses version 2.4.456<br/>- Chrome < 109 automatically uses version 2.6.347<br/>- Note: ReadOnly and Watermark cannot be used in these two compatibility modes",
61576158
"LocalFileName": "local PDF file path"
61586159
},
6160+
"BootstrapBlazor.Server.Components.Samples.PdfViewers": {
6161+
"PdfViewerTitle": "PDFViewer",
6162+
"PdfViewerDescription": "Open the PDF file in the component to read its contents",
6163+
"PdfViewerNormalTitle": "Basic usage",
6164+
"PdfViewerNormalIntro": "Load a PDF file by setting the <code>Url</code> parameter"
6165+
},
61596166
"BootstrapBlazor.Server.Components.Samples.VideoPlayers": {
61606167
"VideoPlayersTitle": "VideoPlayer",
61616168
"VideoPlayersNormalTitle": "Basic usage",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4856,6 +4856,7 @@
48564856
"PulseButton": "心跳按钮 PulseButton",
48574857
"Bluetooth": "蓝牙服务 IBluetoothService",
48584858
"PdfReader": "PDF阅读器 PDF Reader",
4859+
"PdfViewer": "PDF阅读器 PDF Viewer",
48594860
"VideoPlayer": "视频播放器 VideoPlayer",
48604861
"FileViewer": "文件预览器 FileViewer",
48614862
"FlipClock": "卡片翻转时钟 FlipClock",
@@ -6156,6 +6157,12 @@
61566157
"PdfReaderCompatibilityModeTips": "- Chrome < 97 自动使用 2.4.456 版本<br/>- Chrome < 109 自动使用 2.6.347 版本<br/>- 注:ReadOnly 和 Watermark 在这两种兼容模式下不能使用",
61576158
"LocalFileName": "PDF本地文件路径"
61586159
},
6160+
"BootstrapBlazor.Server.Components.Samples.PdfViewers": {
6161+
"PdfViewerTitle": "PDFViewer PDF 阅读器",
6162+
"PdfViewerDescription": "在组件中打开 Pdf 文件阅读其内容",
6163+
"PdfViewerNormalTitle": "基础用法",
6164+
"PdfViewerNormalIntro": "通过设置 <code>Url</code> 参数加载 Pdf 文件"
6165+
},
61596166
"BootstrapBlazor.Server.Components.Samples.VideoPlayers": {
61606167
"VideoPlayersTitle": "VideoPlayer 视频播放器",
61616168
"VideoPlayersNormalTitle": "基础用法",

src/BootstrapBlazor.Server/docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"onscreen-keyboard": "OnScreenKeyboards",
124124
"pagination": "Paginations",
125125
"pdf-reader": "PdfReaders",
126+
"pdf-viewer": "PdfViewers",
126127
"pop-confirm": "PopoverConfirms",
127128
"popover": "Popovers",
128129
"progress": "Progress",
992 KB
Binary file not shown.

0 commit comments

Comments
 (0)