bbm Posted March 19, 2021 Posted March 19, 2021 Hi, I use the TUniPDFFrame component. A PDF document is displayed in this component. During the manually started printing process, a progress dialog appears with a done button. Is there a way to automatically close this dialog after printing is complete? Best regards Quote
Sherzod Posted March 20, 2021 Posted March 20, 2021 16 hours ago, bbm said: I use the TUniPDFFrame component. A PDF document is displayed in this component. During the manually started printing process, a progress dialog appears with a done button. Is there a way to automatically close this dialog after printing is complete? Hello, I'll check it. Quote
Wilton Ergon Posted April 26, 2021 Posted April 26, 2021 I also realized this problem, uni-1.90.0.1547 Quote
Roberto Nicchi Posted September 22, 2021 Posted September 22, 2021 I still see this problem in 1.90.0.1551 The progress dialog should automatically close if the print is completed or if cancelled. Now ramains always visible. Quote
KingOrmon Posted August 6, 2024 Posted August 6, 2024 On 3/20/2021 at 6:15 AM, Sherzod said: Hello, I'll check it. Hi, Any solution ? Regards Quote
Frederick Posted June 27, 2025 Posted June 27, 2025 What happened? Clients are complaining that the application is not polished because of this issue. Quote
Sherzod Posted July 17, 2025 Posted July 17, 2025 Hello @bbm @SISBLU Software @Wilton Ergon @Roberto Nicchi @KingOrmon @Frederick One possible solution: 1. MainForm.Script -> function setupAutoClosePrintDialog(iframe, delayMs) { if (!iframe || !iframe.contentWindow || !iframe.contentDocument) return; function watchPrintDialog() { var doc = iframe.contentDocument; var timer = null; if (iframe.__pdfPrintObserver) { iframe.__pdfPrintObserver.disconnect(); iframe.__pdfPrintObserver = null; } var observer = new MutationObserver(function() { var percentSpan = doc.querySelector('.dialog [data-l10n-id="print_progress_percent"]'); var btn = doc.querySelector('.dialog #printCancel.overlayButton'); if ( percentSpan && percentSpan.textContent.trim() === "100%" && btn && btn.offsetParent !== null ) { if (timer) return; timer = setTimeout(function() { var percentAgain = doc.querySelector('.dialog [data-l10n-id="print_progress_percent"]'); var btnAgain = doc.querySelector('.dialog #printCancel.overlayButton'); if ( percentAgain && percentAgain.textContent.trim() === "100%" && btnAgain && btnAgain.offsetParent !== null ) { btnAgain.click(); observer.disconnect(); iframe.__pdfPrintObserver = null; //console.log("Dialog auto-closed at 100% (no text check, delay: " + delayMs + " ms)"); } }, delayMs || 2000); } else { if (timer) { clearTimeout(timer); timer = null; } } }); observer.observe(doc.body, { childList: true, subtree: true }); iframe.__pdfPrintObserver = observer; } iframe.contentWindow.addEventListener('beforeprint', watchPrintDialog); } 2. Usage, OnFrameLoaded -> procedure TMainForm.UniPDFFrame1FrameLoaded(Sender: TObject); begin JSInterface.JSCallGlobalDefer('setupAutoClosePrintDialog', [JSInterface.JSStatement((Sender as TUniPDFFrame).JSName + '.iframe')], 1000); end; Quote
Frederick Posted July 17, 2025 Posted July 17, 2025 Thanks for the code. I put the script code in the MainForm but the event code in another form since the report is printed from the latter. Unfortunately, the dialogue box still remains on the screen after the print button is clicked and the print dialogue box is then cancelled. Note: Even if I put the script code in the same form as the TUniPDFFrame control, the result is still the same. Please see the attached video. dialogboxinpdfframe.mp4 Quote
Sherzod Posted July 17, 2025 Posted July 17, 2025 @Frederick Have you attached the code to the OnFrameLoaded event? Quote
Frederick Posted July 17, 2025 Posted July 17, 2025 The code is as you have provided:- procedure TfrmReports.pdfFrameFrameLoaded(Sender: TObject); begin JSInterface.JSCallGlobalDefer('setupAutoClosePrintDialog', [JSInterface.JSStatement((Sender as TUniPDFFrame).JSName + '.iframe')], 1000); end; Quote
Frederick Posted July 17, 2025 Posted July 17, 2025 I'll research it further since on a bare bones project, the dialogue box is not seen. Quote
fraxzi Posted July 21, 2025 Posted July 21, 2025 Hi @Sherzod, I adapted this. It works on my side. Thanks! 1 Quote
KingOrmon Posted July 27, 2025 Posted July 27, 2025 Hi, I see a new versión of PDF.js that removes this message automatically ? See this link: https://mozilla.github.io/pdf.js/web/viewer.html Quote
KingOrmon Posted July 27, 2025 Posted July 27, 2025 55 minutes ago, KingOrmon said: Hi, I see a new versión of PDF.js that removes this message automatically ? See this link: https://mozilla.github.io/pdf.js/web/viewer.html BTW, Would be good an update for PDF.js included in unigui ? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.