Enhance PDF viewing experience with new document viewer
- Replaced button in `Details.cshtml` with a link to a new document viewer page. - Created `DocumentViewer.cshtml` to display PDFs using an iframe, with a back button and a link to an experimental DevExpress viewer. - Introduced `DocumentViewerModel` in `DocumentViewer.cshtml.cs` for handling invoice ID and PDF URL. - Updated `OnGetAsync` in `ViewPdf.cshtml.cs` to set `Content-Disposition` to inline for better PDF rendering in the browser.
This commit is contained in:
@@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
@if (!string.IsNullOrEmpty(Model.Invoice?.ResultFilePath))
|
@if (!string.IsNullOrEmpty(Model.Invoice?.ResultFilePath))
|
||||||
{
|
{
|
||||||
<button class="btn btn-primary mb-3 ms-2"
|
<a class="btn btn-primary mb-3 ms-2"
|
||||||
onclick="openPdfViewer(@Model.Invoice.Id)">
|
href="/Invoices/DocumentViewer?id=@Model.Invoice.Id">
|
||||||
<i class="dx-icon-pdffile"></i> Ergebnis anzeigen
|
<i class="dx-icon-pdffile"></i> Ergebnis anzeigen
|
||||||
</button>
|
</a>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (Model.Invoice is null)
|
@if (Model.Invoice is null)
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
@page
|
||||||
|
@model DXApp.TemplateKitProject.Pages.Invoices.DocumentViewerModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Dokument Viewer";
|
||||||
|
var pdfUrl = Model.PdfUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="container-fluid" style="height:100vh; padding:0;">
|
||||||
|
<div class="d-flex align-items-center justify-content-between p-3 border-bottom">
|
||||||
|
<h5 class="m-0">Rechnung @Model.Id - Dokument</h5>
|
||||||
|
<div>
|
||||||
|
<a class="btn btn-secondary me-2" href="/Invoices">Zurück zur Übersicht</a>
|
||||||
|
<!-- Später: Button um DevExpress Viewer zu öffnen -->
|
||||||
|
<a class="btn btn-outline-primary" href="/Invoices/DocumentViewerDevExpress?id=@Model.Id">
|
||||||
|
DevExpress Viewer (experimental)
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="height:calc(100vh - 64px);">
|
||||||
|
@* Solide, funktionierende Baseline: Browser-internen PDF-Renderer verwenden *@
|
||||||
|
<iframe id="pdf-viewer-iframe"
|
||||||
|
src="@pdfUrl"
|
||||||
|
style="width:100%; height:100%; border: none;"
|
||||||
|
title="PDF Viewer"></iframe>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@* Hinweis:
|
||||||
|
- Diese Seite zeigt aktuell das PDF per einfachem iframe (funktioniert zuverlässig).
|
||||||
|
- Nächster Commit: wir ersetzen iframe durch DevExpress WebDocumentViewer oder laden diesen zusätzlich.
|
||||||
|
- Der Link "DevExpress Viewer (experimental)" ist ein Platzhalter; wir implementieren die Route /Invoices/DocumentViewerDevExpress in einem der nächsten Schritte.
|
||||||
|
*@
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace DXApp.TemplateKitProject.Pages.Invoices;
|
||||||
|
|
||||||
|
public class DocumentViewerModel : PageModel
|
||||||
|
{
|
||||||
|
[BindProperty(SupportsGet = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string PdfUrl => $"/Invoices/ViewPdf?id={Id}";
|
||||||
|
|
||||||
|
public void OnGet()
|
||||||
|
{
|
||||||
|
// Keine serverseitige Logik nötig für die erste Version.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,6 @@ public class ViewPdfModel : PageModel
|
|||||||
|
|
||||||
public async Task<IActionResult> OnGetAsync(int id)
|
public async Task<IActionResult> OnGetAsync(int id)
|
||||||
{
|
{
|
||||||
// Sicherheit: defensive checks, gleiche Logik wie CustomReportStorageWebExtension
|
|
||||||
var invoice = await _db.ZugferdInvoices
|
var invoice = await _db.ZugferdInvoices
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.FirstOrDefaultAsync(i => i.Id == id);
|
.FirstOrDefaultAsync(i => i.Id == id);
|
||||||
@@ -35,6 +34,10 @@ public class ViewPdfModel : PageModel
|
|||||||
var bytes = await System.IO.File.ReadAllBytesAsync(invoice.ResultFilePath);
|
var bytes = await System.IO.File.ReadAllBytesAsync(invoice.ResultFilePath);
|
||||||
_logger.LogInformation("ViewPdf: Invoice {Id} ausgeliefert ({Size} Bytes).", id, bytes.Length);
|
_logger.LogInformation("ViewPdf: Invoice {Id} ausgeliefert ({Size} Bytes).", id, bytes.Length);
|
||||||
|
|
||||||
return File(bytes, "application/pdf", $"{Path.GetFileName(invoice.ResultFilePath)}");
|
// Wichtig: keine "attachment" Content-Disposition setzen
|
||||||
|
// wir setzen inline (oder lassen es weg) damit Browser im Viewer darstellt
|
||||||
|
Response.Headers["Content-Disposition"] = $"inline; filename=\"{Path.GetFileName(invoice.ResultFilePath)}\"";
|
||||||
|
|
||||||
|
return File(bytes, "application/pdf");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user