47 lines
1.3 KiB
Plaintext

@page "/testpdf"
@inject HttpClient Http
@inject IJSRuntime JS
<h3>Visualizador PDF de prueba (servidor + local + descarga)</h3>
<div class="mb-3">
<button class="btn btn-primary me-2" @onclick="SavePdf">
<i class="fas fa-download me-1"></i> Guardar
</button>
<button class="btn btn-success me-2" @onclick="ViewPdf">
<i class="fas fa-eye me-1"></i> Ver
</button>
</div>
@if (!string.IsNullOrEmpty(LocalPdfPath))
{
<iframe src="@LocalPdfPath" width="100%" height="800px" style="border: 1px solid #ddd;"></iframe>
}
@code {
private string LocalPdfPath;
private async Task SavePdf()
{
string path = @"C:\temp\PresupuestoTest.pdf";
if (!Directory.Exists(@"C:\temp"))
Directory.CreateDirectory(@"C:\temp");
// ✅ 1. Llamar al endpoint de API para generar PDF
var pdfBytes = await Http.GetByteArrayAsync("http://localhost:5243/api/PdfTest/test"); // Cambia a tu URL real
// ✅ 2. Guardar en disco
System.IO.File.WriteAllBytes(path, pdfBytes);
// ✅ 3. Descargar al usuario
await JS.InvokeVoidAsync("saveAsFile", "PresupuestoTest.pdf", Convert.ToBase64String(pdfBytes));
}
private void ViewPdf()
{
// 👉 Cargar el archivo guardado
LocalPdfPath = "/pdf/DemoTest.pdf";
}
}