@page "/testpdf" @inject HttpClient Http @inject IJSRuntime JS

Visualizador PDF de prueba (servidor + local + descarga)

@if (!string.IsNullOrEmpty(LocalPdfPath)) { } @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"; } }