Created
January 29, 2024 11:08
-
-
Save bjoerntx/f3e8778f72f2f76a724291722fab237c to your computer and use it in GitHub Desktop.
This file contains 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
@using Microsoft.AspNetCore.Components.Web | |
@using Microsoft.JSInterop | |
@inject IJSRuntime JsRuntime | |
@inject NavigationManager Navigator | |
<script src="@(BasePath)TextControl/GetResource?Resource=minimized.tx-viewer.min.js"></script> | |
<script src="@(BasePath)TextControl/GetResource?Resource=minimized.tx-viewer-component.min.js"></script> | |
<tx-document-viewer | |
id="viewer1" | |
settings='{"documentData":"VGV4dCBDb250cm9s", "dock":1, "basePath":"@(BasePath?.TrimEnd('/'))"}'> | |
</tx-document-viewer> | |
@code | |
{ | |
[Parameter] | |
public string? BasePath { get; set; } | |
private DotNetObjectReference<TXDocumentViewer> DotNetReference => DotNetObjectReference.Create(this); | |
private IJSObjectReference? _txdocumentviewer; | |
protected override async Task OnAfterRenderAsync(bool firstRender) | |
{ | |
if (firstRender) | |
{ | |
_txdocumentviewer = await JsRuntime.InvokeAsync<IJSObjectReference>("import", "./scripts/txdocumentviewer.js"); | |
} | |
} | |
[JSInvokable("LoadDocumentFromFile")] | |
public void LoadDocumentFromFile(string filename) | |
{ | |
// check if the file exists | |
if (!System.IO.File.Exists(filename)) | |
{ | |
return; | |
} | |
// load the file into a byte array | |
byte[] bDocument = System.IO.File.ReadAllBytes(filename); | |
// invoke the JS function 'loadDocument' to load back to the modified document | |
_txdocumentviewer?.InvokeVoidAsync("loadDocument", new object[] { Convert.ToBase64String(bDocument), filename }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment