Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created January 24, 2025 16:00
Show Gist options
  • Save bjoerntx/2d7d9b61515613d4e431ab1650a2b6e3 to your computer and use it in GitHub Desktop.
Save bjoerntx/2d7d9b61515613d4e431ab1650a2b6e3 to your computer and use it in GitHub Desktop.
@page "/"
@rendermode @(new InteractiveServerRenderMode(false))
<PageTitle>TX Text Control for Blazor</PageTitle>
<h1>Hello, Blazor!</h1>
<TXTextControl.Web.Blazor.DocumentEditor.DocumentEditor @ref="_documentEditor" onload="@DocumentEditorLoaded" />
<button class="btn btn-primary mt-5" @onclick="ButtonLoad">
Load Document
</button>
<button class="btn btn-primary mt-5" @onclick="ButtonSave">
Save as PDF
</button>
@if (!string.IsNullOrEmpty(ReturnMessage))
{
<div class="alert alert-primary mt-5" role="alert">
@ReturnMessage
</div>
}
@code {
private TXTextControl.Web.Blazor.DocumentEditor.DocumentEditor _documentEditor;
private string ReturnMessage { get; set; } = "";
private async Task DocumentEditorLoaded()
{
try
{
await _documentEditor.LoadDocumentAsync(
"<html><body><h1>Welcome to TX Text Control</h1><p>This is a sample document.</p></body></html>",
TXTextControl.Web.StringStreamType.HTMLFormat
);
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error loading document: {ex.Message}");
}
}
private async Task ButtonLoad()
{
try
{
await _documentEditor.LoadDocumentAsync("sample.docx", TXTextControl.Web.StreamType.WordprocessingML);
ReturnMessage = "Document loaded successfully.";
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error loading document: {ex.Message}");
}
}
private async Task ButtonSave()
{
try
{
await _documentEditor.SaveDocumentAsync("sample.pdf", TXTextControl.Web.StreamType.AdobePDF);
ReturnMessage = "Document saved successfully.";
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error saving document: {ex.Message}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment