Refactor signature handling and PDF export logic
Refactored the signature handling process by introducing a new `Report` instance creation step in the `SignatureApplied` block to streamline signed report generation. Added a validation check in `ExportSignedPdfAsync` to ensure the `Report` object is not null before proceeding with export. Removed redundant code for manual signed report creation and simplified the export logic by directly invoking `reportViewer!.ExportToAsync`. Incremented `ViewerKey` to refresh the report viewer after signing.
This commit is contained in:
@@ -286,8 +286,10 @@
|
||||
|
||||
PopupValidationMessage = null;
|
||||
SignatureValidationMessage = null;
|
||||
Report = CreateSignedReportInstance(signatureDataUrl, SignerFullName.Trim(), SignerPosition.Trim(), SignaturePlace.Trim());
|
||||
SignatureApplied = true;
|
||||
SignaturePopupVisible = false;
|
||||
ViewerKey++;
|
||||
}
|
||||
|
||||
async Task<string?> GetActiveSignatureDataUrlAsync() {
|
||||
@@ -303,31 +305,14 @@
|
||||
}
|
||||
|
||||
async Task ExportSignedPdfAsync() {
|
||||
if(!SignatureApplied) {
|
||||
if(!SignatureApplied || Report is null) {
|
||||
SignatureValidationMessage = "Bitte fuegen Sie die Unterschrift zuerst zum Bericht hinzu.";
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
SignatureValidationMessage = null;
|
||||
|
||||
var signatureDataUrl = await GetActiveSignatureDataUrlAsync();
|
||||
if(string.IsNullOrWhiteSpace(signatureDataUrl)) {
|
||||
SignatureValidationMessage = "Die Unterschrift konnte nicht gelesen werden.";
|
||||
return;
|
||||
}
|
||||
|
||||
var signedKey = $"{EnvelopeKey}_signed";
|
||||
var signedReport = new XtraReport();
|
||||
var detail = new DevExpress.XtraReports.UI.DetailBand();
|
||||
signedReport.Bands.Add(detail);
|
||||
detail.Controls.Add(new DevExpress.XtraReports.UI.XRPdfContent { Source = PdfBytes });
|
||||
ReportStorage.SetData(signedReport, signedKey);
|
||||
Report = ReportStorage.TryGetReport(signedKey, out var stored) ? stored : signedReport;
|
||||
ViewerKey++;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await Task.Delay(300);
|
||||
await reportViewer.ExportToAsync(ExportFormat.Pdf);
|
||||
await reportViewer!.ExportToAsync(ExportFormat.Pdf);
|
||||
} catch(Exception) {
|
||||
SignatureValidationMessage = "Das signierte PDF konnte nicht exportiert werden. Bitte laden Sie die Seite neu und versuchen Sie es erneut.";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user