Rename componente + testing
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
|
||||
@@ -24,12 +24,24 @@
|
||||
<option value="800px">800</option>
|
||||
<option value="1000px">1000</option>
|
||||
</select>
|
||||
@* <span class="input-group-text">Compo</span>
|
||||
<select class="form-select" @bind="@CompoSel">
|
||||
<option value="1">PdfDisplay</option>
|
||||
<option value="2">PdfViewer</option>
|
||||
</select> *@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<PdfViewer Width="100%" Height="@HeightSel" PdfUrl="@($"test/{FileSel}")"></PdfViewer>
|
||||
<PdfDisplay Width="100%" Height="@HeightSel" PdfUrl="@($"test/{FileSel}")"></PdfDisplay>
|
||||
@* @if (CompoSel == 1)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
<PdfDisplay Width="100%" Height="@HeightSel" PdfUrl="@($"test/{FileSel}")"></PdfDisplay>
|
||||
} *@
|
||||
<p class="card-text">Selezione: <b>@FileSel</b></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,29 @@
|
||||
#if false
|
||||
using CA.Blazor.Pdf;
|
||||
using CA.Blazor.Pdf.Extensions;
|
||||
#endif
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace EgwCoreLib.BlazorTest.Pages
|
||||
{
|
||||
public partial class TestPdfViewer
|
||||
{
|
||||
#region Public Fields
|
||||
|
||||
public int CompoSel = 1;
|
||||
|
||||
#endregion Public Fields
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public string PdfBase64 { get; set; } = "";
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
protected string FileSel
|
||||
{
|
||||
get => fileSel;
|
||||
@@ -10,10 +32,12 @@ namespace EgwCoreLib.BlazorTest.Pages
|
||||
if (fileSel != value)
|
||||
{
|
||||
fileSel = value;
|
||||
ReloadData().ConfigureAwait(false);
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected string HeightSel
|
||||
{
|
||||
get => heightSel;
|
||||
@@ -26,7 +50,70 @@ namespace EgwCoreLib.BlazorTest.Pages
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Inject]
|
||||
protected NavigationManager NavMan { get; set; } = null!;
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await ReloadData();
|
||||
await Task.Delay(1);
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private string fileSel { get; set; } = "File01.pdf";
|
||||
private string heightSel { get; set; } = "400px";
|
||||
|
||||
private string baseUri = "";
|
||||
private string fileUrl = "";
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private async Task<string> GetBase64Pdf(string apiUrl)
|
||||
{
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
httpClient.BaseAddress = new Uri(NavMan.BaseUri);
|
||||
|
||||
// Make the API request to get the PDF content
|
||||
var response = await httpClient.GetAsync(apiUrl);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
// Convert the response content to Base64
|
||||
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
|
||||
var base64String = Convert.ToBase64String(pdfBytes);
|
||||
return $"data:application/pdf;base64,{base64String}";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle error scenarios based on your application needs For simplicity, we
|
||||
// return an empty string in case of an error
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ReloadData()
|
||||
{
|
||||
baseUri = NavMan.BaseUri;
|
||||
fileUrl = $"{baseUri}/test/{FileSel}";
|
||||
|
||||
#if false
|
||||
// Call the helper method to retrieve the Base64-encoded PDF content
|
||||
PdfBase64 = await GetBase64Pdf(apiUrl);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -60,5 +60,7 @@
|
||||
</script>
|
||||
|
||||
<script src="~/lib/Chart.js/chart.js"></script>
|
||||
<script src="~/lib/pdfobject/pdfobject.min.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
|
||||
using EgwCoreLib.BlazorTest;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
<Content Include="PdfViewer.razor.js" />
|
||||
<Content Include="PdfDisplay.razor.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -66,7 +66,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.11" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components" Version="6.0.14" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.14" />
|
||||
<PackageReference Include="ZXing.Net" Version="0.16.9" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ using ZXingBlazor.Components;
|
||||
|
||||
namespace EgwCoreLib.Razor
|
||||
{
|
||||
public partial class PdfViewer
|
||||
public partial class PdfDisplay
|
||||
{
|
||||
/// <summary>
|
||||
/// URL del documento da mostrare
|
||||
@@ -43,7 +43,7 @@ namespace EgwCoreLib.Razor
|
||||
{
|
||||
if (!firstRender) return;
|
||||
|
||||
module = await JS.InvokeAsync<IJSObjectReference>("import", "./_content/EgwCoreLib.Razor/PdfViewer.razor.js");
|
||||
module = await JS.InvokeAsync<IJSObjectReference>("import", "./_content/EgwCoreLib.Razor/PdfDisplay.razor.js");
|
||||
isMobile = await JS.InvokeAsync<bool>("isDevice");
|
||||
}
|
||||
catch
|
||||
Reference in New Issue
Block a user