-
-
Notifications
You must be signed in to change notification settings - Fork 363
feat(PdfViewer): add PdfViewer component #6164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/BootstrapBlazor.Server/Components/Samples/PdfViewers.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| @page "/pdf-viewer" | ||
| @inject IStringLocalizer<PdfViewers> Localizer | ||
|
|
||
| <h3>@Localizer["PdfViewerTitle"]</h3> | ||
|
|
||
| <h4>@Localizer["PdfViewerDescription"]</h4> | ||
|
|
||
| <PackageTips Name="BootstrapBlazor.PdfViewer" /> | ||
|
|
||
| <DemoBlock Title="@Localizer["PdfViewerNormalTitle"]" Introduction="@Localizer["PdfViewerNormalIntro"]" Name="Normal"> | ||
| <PdfViewer Url="./samples/pdf-viewer.pdf" Height="620px"></PdfViewer> | ||
| </DemoBlock> | ||
268 changes: 268 additions & 0 deletions
268
src/BootstrapBlazor.Server/Components/Samples/PdfViewers.razor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| using System.ComponentModel; | ||
|
|
||
| namespace BootstrapBlazor.Server.Components.Samples; | ||
|
|
||
| /// <summary> | ||
| /// PdfViewers | ||
| /// </summary> | ||
| 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; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// GetAttributes | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| 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 = " — " | ||
| } | ||
| ]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.