From 0f167d731e9fc1468dc6dc67682ecaafe428f591 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 30 Sep 2026 17:02:05 +0200 Subject: [PATCH] Add PDF printing functionality to editor components Enabled PDF printing in `SenderPdfImageEditor` and `SenderPdfImageEditorToolbar`. Added `CanPrintPdf` property to determine print availability and a new `OnPrintPdfAsync` method for handling print logic via JavaScript interop. Updated the toolbar with a "Print" button that triggers the print functionality. Implemented the `printDataUrlPdf` function in `envelope-editor.js` to handle printing from a data URL. This function creates an iframe, loads the PDF, and invokes the browser's print functionality with proper cleanup of resources. --- .../PdfEditor/SenderPdfImageEditor.razor | 16 +++- .../SenderPdfImageEditorToolbar.razor | 14 +++- .../wwwroot/js/envelope-editor.js | 77 +++++++++++++++++++ 3 files changed, 105 insertions(+), 2 deletions(-) diff --git a/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditor.razor b/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditor.razor index 90a64d16..f411ffcb 100644 --- a/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditor.razor +++ b/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditor.razor @@ -25,7 +25,9 @@ ZoomIn="OnZoomInAsync" SetZoomPercent="OnSetZoomPercentAsync" CanDownloadPdf="@CanDownloadPdf" - DownloadPdf="OnDownloadPdfAsync" /> + CanPrintPdf="@CanPrintPdf" + DownloadPdf="OnDownloadPdfAsync" + PrintPdf="OnPrintPdfAsync" /> } @@ -150,6 +152,7 @@ private const int MaxZoomPercent = 300; private const int ZoomStepPercent = 5; private bool CanDownloadPdf => !string.IsNullOrWhiteSpace(PdfDataUrl); + private bool CanPrintPdf => !string.IsNullOrWhiteSpace(PdfDataUrl); private static string GetFieldStyle(SenderPdfFieldOverlay field, double pageWidthPt, double pageHeightPt) { @@ -397,6 +400,17 @@ "application/pdf"); } + private async Task OnPrintPdfAsync() + { + if (string.IsNullOrWhiteSpace(PdfDataUrl)) + return; + + await JSRuntime.InvokeVoidAsync( + "envelopeEditor.printDataUrlPdf", + PdfDataUrl, + "application/pdf"); + } + private void OnEditorMouseUp(MouseEventArgs args) { _draggedFieldIndex = null; diff --git a/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditorToolbar.razor b/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditorToolbar.razor index 11087b8b..f1217186 100644 --- a/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditorToolbar.razor +++ b/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Components/PdfEditor/SenderPdfImageEditorToolbar.razor @@ -86,7 +86,7 @@
-