Suppress pinter error dialog

In my apps I load some html into a WKWebview and print that with an NSPrintOperation into a PDF. Now and then I get an error “Error while printing”. This error comes from macOS and not from my app. How do I suppress the error?

MBS from 13.10.2025 and latest Xojo.

Sorry, this is not my message box.
Do you have something in the app?

Also can you reproduce it?
If yes, maybe run the app via terminal to catch error messages or use console.log to maybe find a message from WebKit about what failed.

As I said above: no, there is no error message like that in my app. Also the error message only shows up occasionally. Here is the log. The error is from 14:32:

log.txt.zip (92.7 KB)

How are you doing the printing? The interesting bit reads like it could be a bug in the Xojo framework, but I was certain you weren’t using the HTMLViewer PrintToPDF function because of its deficiencies.

2025-12-01 14:32:28.583+0100  --  MAX Messages.debug (MAX Messages.debug) -- fgetattrlist failed: #9: Bad file descriptor
2025-12-01 14:32:28.584+0100  --  MAX Messages.debug (XojoFramework) -- reportPrinter.Notify 1
2025-12-01 14:32:28.584+0100  --  MAX Messages.debug (XojoFramework) -- reportPrinter.Notify uuid: {41CE9767-33B3-4D1F-8EEB-EE677995414A} filename: {41CE9767-33B3-4D1F-8EEB-EE677995414A}
2025-12-01 14:32:28.585+0100  --  MAX Messages.debug (XojoFramework) -- reportPrinter.CreatePDF 1
2025-12-01 14:32:28.597+0100  --  MAX Messages.debug (MAX Messages.debug) -- fgetattrlist failed: #9: Bad file descriptor
2025-12-01 14:32:28.598+0100  --  MAX Messages.debug (CoreServicesInternal) -- CFURLResolveBookmarkData
1 Like

No, this is a WKWebviewer with the following code in DidFinishNavigation:

PrintStart = DateTime.Now.SecondsFrom1970
TimeoutTimer.RunMode = Timer.RunModes.Multiple

Globals.theErrorLog.LogitemToConsole(currentMethodName + " 1")
try
Thread.SleepCurrent(10)

TempItem = getTempFolderitem

'normal print
if TempItem = Nil then
Globals.theErrorLog.logitem(currentMethodName + " no temp item")
NotificationManager.Post(“PDFCreatedError”, MakeDictionary(“UUID”:UUID))
Return
end if

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)
if PrintOperation = Nil then
Thread.SleepCurrent(100)
Break 'don’t know why I get an NOE here
PrintOperation = browser.printOperation(PrintInfo)
end if

try
AddHandler PrintOperation.printOperationDidRun, AddressOf PrintOperationFinished
catch err as RuntimeException
if err.Message = “Attempting to add a handler for an event that was already handled.” then
Globals.theErrorLog.logitem(currentMethodName + " runtime exception when adding print finished handler")
NotificationManager.Post(“PDFCreatedError”, MakeDictionary(“UUID”:UUID))
end if
end try
Thread.SleepCurrent(10)
PrintOperation.showsPrintPanel = False
PrintOperation.showsProgressPanel = False
PrintOperation.runOperationModalForWindow(Self)

catch err as NilObjectException
Globals.theErrorLog.logitem(currentMethodName + " nil object exception")
NotificationManager.Post(“PDFCreatedError”, MakeDictionary(“UUID”:UUID))

end try

Globals.theErrorLog.LogitemToConsole(currentMethodName + " 2")

The file for printing shouldn’t make problems:

Private Function getTempFolderitem() As FolderItem

Globals.theErrorLog.LogitemToConsole(currentMethodName + " 1")
'create a temp file

Dim theTempFile As FolderItem = SpecialFolder.Temporary.Child(UUID)
if not theTempFile.Exists then theTempFile.CreateFolder
theTempFile = theTempFile.Child(UUID)
if theTempFile.Exists then theTempFile.reallyDelete

Globals.theErrorLog.LogitemToConsole(currentMethodName + " 2")

Return theTempFile
End Function

What does a bad file descriptor mean? The Goggle is rather generic with what that is. Today I mad only one PDF.