62 lines
2.3 KiB
Plaintext
62 lines
2.3 KiB
Plaintext
@page "/pdfviewer"
|
|
@using DevExpress.Blazor.PdfViewer
|
|
@using System.Reflection
|
|
|
|
<head>
|
|
<link rel="stylesheet" href=@AppendVersion("_content/DevExpress.Blazor.Viewer/css/dx-blazor-viewer-components.bs5.css")>
|
|
</head>
|
|
|
|
<div style="display: flex">
|
|
|
|
<div id="overviewDemoDropZone" class="card custom-drop-zone rounded-3 w-100 m-0">
|
|
<span class="drop-file-icon mb-3"></span>
|
|
<span class="drop-file-label">Drag and Drop File Here</span><span class="m-1">or</span>
|
|
<DxButton Id="overviewDemoSelectButton"
|
|
CssClass="m-1"
|
|
RenderStyle="ButtonRenderStyle.Primary"
|
|
Text="Select File" />
|
|
</div>
|
|
<DxFileInput @ref="fileInput"
|
|
AcceptedFileTypes="@ALLOWED_FILE_TYPES"
|
|
AllowedFileExtensions="@ALLOWED_FILE_TYPES"
|
|
CssClass="w-100"
|
|
ExternalDropZoneCssSelector="#overviewDemoDropZone"
|
|
ExternalDropZoneDragOverCssClass="custom-drop-zone-hover"
|
|
ExternalSelectButtonCssSelector="#overviewDemoSelectButton"
|
|
FilesUploading="OnFilesUploading"
|
|
MaxFileSize="2000000">
|
|
</DxFileInput>
|
|
<div style="width: 4000px">
|
|
<DxPdfViewer CssClass="w-100 pdf-viewer" DocumentContent="DocumentContent" ZoomLevel=1/>
|
|
</div>
|
|
</div>
|
|
|
|
@code {
|
|
readonly List<string> ALLOWED_FILE_TYPES = new List<string> { ".pdf" };
|
|
DxFileInput fileInput;
|
|
byte[] DocumentContent { get; set; }
|
|
|
|
private Stream GetFileStream() => File.OpenRead(@"D:\E-RechnungA3.pdf");
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
|
using (Stream stream = GetFileStream())
|
|
using (var binaryReader = new BinaryReader(stream))
|
|
DocumentContent = binaryReader.ReadBytes((int)stream.Length);
|
|
}
|
|
|
|
protected async Task OnFilesUploading(FilesUploadingEventArgs args)
|
|
{
|
|
using (MemoryStream stream = new MemoryStream())
|
|
{
|
|
IFileInputSelectedFile file = args.Files[0];
|
|
await file.OpenReadStream(file.Size).CopyToAsync(stream);
|
|
DocumentContent = stream.ToArray();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
|
|
private string AppendVersion(string path) => $"{path}?v={typeof(DevExpress.Blazor.ResourcesConfigurator).Assembly.GetName().Version}";
|
|
}
|