Skip to content

Commit

Permalink
!3792 doc(#I6B872): update PdfReader demos
Browse files Browse the repository at this point in the history
* doc(#I6B872): update PdfReader demos
  • Loading branch information
densen2014 authored and ArgoZhang committed Jan 26, 2023
1 parent 5998f46 commit db3b73c
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 20 deletions.
47 changes: 31 additions & 16 deletions src/BootstrapBlazor.Shared/Demos/PdfReader/PdfReaderAdvanced.razor
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="row mb-3">
<div class="col-12">
<BootstrapInputGroup>
<BootstrapInputGroupLabel @bind-Value="@Search" />
<BootstrapInputGroupLabel @bind-Value="@Search" DisplayText="@Localizer["PdfReaderAdvancedSearchLabel"]" />
<BootstrapInput @bind-Value="@Search" />
<Button Icon="fa-solid fa-magnifying-glass" OnClick="ApplySearch"></Button>
</BootstrapInputGroup>
Expand All @@ -26,20 +26,24 @@
<div class="row mb-3">
<div class="col-12">
<BootstrapInputGroup>
<BootstrapInputGroupLabel @bind-Value="@Filename" />
<BootstrapInputGroupLabel @bind-Value="@Filename" DisplayText="@Localizer["PdfReaderAdvancedFilenameLabel"]" />
<BootstrapInput @bind-Value="@Filename" />
<Button Color="Color.Primary" OnClick="ApplySearch">@Localizer["PdfReaderAdvancedRefreshPage"]</Button>
</BootstrapInputGroup>
</div>
</div>
<div class="row mb-3 form-inline">
<div class="col-6 col-sm-4 col-md-3 col-lg-auto">
<Switch @bind-Value="@StreamMode" ShowLabel="true" />
<Switch @bind-Value="@StreamMode" ShowLabel="true" DisplayText="@Localizer["PdfReaderAdvancedStreamModeLabel"]"/>
</div>
<div class="col-6 col-sm-4 col-md-3 col-lg-auto">
<Switch @bind-Value="@ReadOnly" ShowLabel="true" DisplayText="@Localizer["PdfReaderAdvancedReadOnlyLabel"]" ShowLabelTooltip="true" OnValueChanged="_=>ApplySearch()" />
</div>
<BootstrapInput @bind-Value="@Watermark" DisplayText="@Localizer["PdfReaderAdvancedWatermarkLabel"]" />
</div>

<PdfReader @ref="PdfReader"
Filename="@(StreamMode?FilenameStream:Filename)"
FileName="@(StreamMode?FilenameStream:Filename)"
StreamMode="StreamMode"
Page=@Page
Zoom=@Zoom
Expand All @@ -56,9 +60,15 @@
[DisplayName("流模式")]
private bool StreamMode { get; set; }

private EnumZoomMode Zoom { get; set; } = EnumZoomMode.Auto;
[DisplayName("禁用复制/打印/下载")]
public bool ReadOnly { get; set; }

[DisplayName("水印内容")]
public string Watermark { get; set; } = "www.blazor.zone";

private EnumPageMode Pagemode { get; set; } = EnumPageMode.Thumbs;
private EnumZoomMode Zoom { get; set; } = EnumZoomMode.PageHeight;

private EnumPageMode Pagemode { get; set; } = EnumPageMode.None;

[DisplayName("文件相对路径或者URL")]
private string Filename { get; set; } = "/samples/sample.pdf";
Expand All @@ -76,15 +86,17 @@
{
Zoom = Zoom switch
{
EnumZoomMode.Auto => EnumZoomMode.PageFit,
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 PdfReader.Refresh();
await Refresh();
}

private async Task ApplyPagemode()
Expand All @@ -97,31 +109,34 @@
EnumPageMode.Layers => EnumPageMode.None,
_ => EnumPageMode.Thumbs
};
await PdfReader.Refresh(Search, Page, Pagemode, Zoom);
await Refresh();
}

async Task Refresh()
{
if (PdfReader != null)
await PdfReader.Refresh(Search, Page, Pagemode, Zoom, ReadOnly, Watermark);
}

private async Task ApplyPage()
{
Search = null;
await PdfReader.Refresh(Search, Page, Pagemode, Zoom);
await Refresh();
}

private async Task ApplyPagePrevious()
{
Page--;
Search = null;
await PdfReader.Refresh(Search, Page, Pagemode, Zoom);
await Refresh();
}

private async Task ApplyPageNext()
{
Page++;
Search = null;
await PdfReader.Refresh(Search, Page, Pagemode, Zoom);
await Refresh();
}

private async Task ApplySearch()
{
await PdfReader.Refresh(Search, Page, Pagemode, Zoom);
}
private async Task ApplySearch() => await Refresh();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@using System.ComponentModel;
@inject IStringLocalizer<PdfReaderCompatibilityMode> Localizer

<Tips>
<div>@((MarkupString)Localizer["PdfReaderCompatibilityModeTips"].Value)</div>
</Tips>

<h6>CompatibilityMode</h6>
<PdfReader FileName=@FileName CompatibilityMode Height="300px" />

<h6>CompatibilityNoneES5</h6>
<PdfReader FileName=@FileName CompatibilityNoneES5 Height="300px" />

@code {
[DisplayName("the file in the wwwroot relative path or url")]
private string FileName { get; set; } = "/samples/sample.pdf";
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@using System.ComponentModel;

<PdfReader Filename=@Filename Height="500px" />
<PdfReader FileName=@Filename Height="500px" />

@code {
[DisplayName("the file in the wwwroot relative path or url")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</BootstrapInputGroup>
</div>
</div>
<PdfReader @ref="PdfReader" Filename="@FilenameStream" StreamMode="true" Height="500px" />
<PdfReader @ref="PdfReader" FileName="@FilenameStream" StreamMode="true" Height="500px" />
</div>

@code {
Expand Down
9 changes: 8 additions & 1 deletion src/BootstrapBlazor.Shared/Locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5990,6 +5990,8 @@
"PdfReaderNomalIntro": "Use Filename parameter displays pdf file from local server, or Stream parameter use file stream for rendering",
"PdfReaderStreamModeText": "Stream mode",
"PdfReaderStreamModeIntro": "read remote files by cross-domain",
"PdfReaderCompatibilityModeText": "Compatibility mode",
"PdfReaderCompatibilityModeIntro": "Compatible with older browsers",
"PdfReaderAdvancedText": "Advanced parameters",
"PdfReaderAdvancedIntro": "Can be use advanced parameters",
"PdfReaderIssue": "Destructive update reference link: remove pdfoobject",
Expand Down Expand Up @@ -6023,7 +6025,12 @@
"PdfReaderAdvancedRefreshPage": "RefreshPage",
"PdfReaderAdvancedStreamModeLabel": "StreamMode",
"PdfReaderAdvancedFilenameLabel": "The file in the wwwroot relative path or url",
"PdfReaderAdvancedSearchLabel": "Search"
"PdfReaderAdvancedSearchLabel": "Search",
"PdfReaderAdvancedReadOnlyLabel": "Disable copy/print/download",
"PdfReaderAdvancedWatermarkLabel": "Watermark content"
},
"BootstrapBlazor.Shared.Demos.PdfReader.PdfReaderCompatibilityMode": {
"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"
},
"BootstrapBlazor.Shared.Samples.VideoPlayers": {
"Title": "VideoPlayer",
Expand Down
10 changes: 9 additions & 1 deletion src/BootstrapBlazor.Shared/Locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -6007,6 +6007,8 @@
"PdfReaderNomalIntro": "Filename 参数显示本服务器pdf文件,或 Stream 参数指定用于渲染的文件流",
"PdfReaderStreamModeText": "流模式",
"PdfReaderStreamModeIntro": "可跨域读取文件",
"PdfReaderCompatibilityModeText": "兼容模式",
"PdfReaderCompatibilityModeIntro": "兼容旧版浏览器",
"PdfReaderAdvancedText": "高级参数",
"PdfReaderAdvancedIntro": "可以使用高级参数",
"PdfReaderIssue": "破坏性更新参考链接: 移除pdfobject",
Expand Down Expand Up @@ -6040,8 +6042,14 @@
"PdfReaderAdvancedRefreshPage": "刷新",
"PdfReaderAdvancedStreamModeLabel": "流模式",
"PdfReaderAdvancedFilenameLabel": "文件相对路径或者URL",
"PdfReaderAdvancedSearchLabel": "搜索"
"PdfReaderAdvancedSearchLabel": "搜索",
"PdfReaderAdvancedReadOnlyLabel": "禁用复制/打印/下载",
"PdfReaderAdvancedWatermarkLabel": "水印内容"
},
"BootstrapBlazor.Shared.Demos.PdfReader.PdfReaderCompatibilityMode": {
"PdfReaderCompatibilityModeTips": "- Chrome < 97 自动使用 2.4.456 版本<br/>- Chrome < 109 自动使用 2.6.347 版本<br/>- 注:ReadOnly 和 Watermark 在这两种兼容模式下不能使用"
},

"BootstrapBlazor.Shared.Samples.VideoPlayers": {
"Title": "VideoPlayer 视频播放器",
"BaseUsageText": "基础用法",
Expand Down
2 changes: 2 additions & 0 deletions src/BootstrapBlazor.Shared/Samples/PdfReaders.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

<DemoBlock Title="@Localizer["PdfReaderStreamModeText"]" Introduction="@Localizer["PdfReaderStreamModeIntro"]" Name="StreamMode" Demo="typeof(Demos.PdfReader.PdfReaderStreamMode)" />

<DemoBlock Title="@Localizer["PdfReaderCompatibilityModeText"]" Introduction="@Localizer["PdfReaderCompatibilityModeIntro"]" Name="CompatibilityMode" Demo="typeof(Demos.PdfReader.PdfReaderCompatibilityMode)" />

<DemoBlock Title="@Localizer["PdfReaderAdvancedText"]" Introduction="@Localizer["PdfReaderAdvancedIntro"]" Name="Advanced" Demo="typeof(Demos.PdfReader.PdfReaderAdvanced)" />

<AttributeTable Items="@GetAttributes()" />
Expand Down

0 comments on commit db3b73c

Please sign in to comment.