Detect when HTMLViewer.Print has completed

Does anyone know of a way of detecting when an HTMLViewer has completed printing and I can remove the file it worked on.

I use a HtmlViewer to create PDFs with the MBS plugin. This defines an event so that I know when the PDF has been created:

'normal print
tempItem = getTempFolderitem

Dim browser As WKWebViewMBS = WKWebViewControlMBS1.WKWebView // your web viewer
Dim PrintInfo As NSPrintInfoMBS = new NSPrintInfoMBS
PrintInfo.SetSaveDestination(tempItem)
PrintInfo.horizontalPagination = PrintInfo.NSAutoPagination
PrintInfo.verticalPagination = PrintInfo.NSAutoPagination
PrintInfo.leftMargin = 50.0
PrintInfo.topMargin = 50.0
PrintInfo.rightMargin = 50.0
PrintInfo.bottomMargin = 50.0

PrintOperation = browser.printOperation(PrintInfo)
AddHandler PrintOperation.printOperationDidRun, AddressOf PrintOperationFinished
Thread.SleepCurrent(10)
PrintOperation.showsPrintPanel = False
PrintOperation.showsProgressPanel = False
PrintOperation.runOperationModalForWindow(Self)

In PrintOperationFinished I check that the file has been created. macOS only, of course. And it only works properly Mojave to BS.

using executejavascript, you may be able to detect onafterprint event ?

@Beatrix_Willius Thanks, I should have said. I don’t have the MBS plugins.

@Jean-Yves_Pochez I’ll take a look at the JS solution, thanks.