Questions for moving to WkWebViewMBS

I’m trying to move to WkWebview for things to come. However, not all features seem to be available.

Old code:

dim thePrefs as WebPreferencesMBS thePrefs = me.preferencesMBS thePrefs.javaScriptCanOpenWindowsAutomatically = False thePrefs.isJavaScriptEnabled = True thePrefs.cacheModel = 0

I found javaScriptCanOpenWindowsAutomatically and isJavaScriptEnabled. But how do I set the cacheModel?

How do I replace the standard font:

[code]dim thePrefs as WebPreferencesMBS
thePrefs = me.preferencesMBS

thePrefs.DefaultFontSize = NSFontMBS.SystemFontSize
dim theFont as String = OSUtils.getAppearanceFont(false)
thePrefs.StandardFontFamily = OSUtils.getSystemFontName(theFont)[/code]

What is the equivalent of loadsImagesAutomatically?

And finally the most important part: How do I replace PrintToPDFFileMBS? The code below

HTMLViewer1.PrintToPDFFileMBS(tempItem, 50, 50, 50, 50)

is the beginning of my PDF routine. I found

WKWebViewMBS.PDFData(byref error as NSErrorMBS) as MemoryBlock

How do I use the function?

Forgot something. I need the equivalent of shouldPrintBackgrounds:

dim thePrefs as WebPreferencesMBS thePrefs = me.preferencesMBS thePrefs.shouldPrintBackgrounds = true

First, I think I could add loadsImagesAutomatically for you.

For printing, you can check

PDFData(byref error as NSErrorMBS) as MemoryBlock

method in WKWebViewMBS class.

Otherwise you can try NSPrintOperationMBS class with your WKWebViewMBS object to print, but not sure if Apple implemented this for Mojave or Big Sur.

Very good. I got PDFData sort of working with:

[code]dim t as NSErrorMBS
Dim data As MemoryBlock = HTMLViewer1.WKWebViewMBS.PDFData(t)

// write file to location
Dim f As FolderItem = GetSaveFolderItem("", “name”)

If f <> Nil then
Dim b As BinaryStream = BinaryStream.Create(f)

b.Write data
End If[/code]

However, I need margins and a decent paper size.

“NSPrintOperation with HtmlViewer” makes a nice white in white pdf on BS. So that one is out.

Not sure about cache model, but in NSURLRequest you can include flag for not caching.

I’m not using NSURLRequest. That part of the code is just a HtmlViewer for viewing message bodies of emails.

I just loaded the latest versions of the plugins. There will be even more questions. Would a replacement guide for htmlviewer stuff be a good idea?

Any news on the printing front? Is it possible or is it not possible? What can I do with the cache model? I only show local data.

We may find something, but maybe time to rewatch the WWDC videos.

Have lots of fun watching the videos.

Well, we do have printOperation as method on WKWebViewMBS class.

How do I get

a) all pages
b) DIN A4
c) margins?

Sorry, I don’t know that.
If print operation doesn’t work, making PDF may be the best way.

Christian, can you please elaborate your answers a tiny little bit. I have html and need to make pdfs from the html. What you do you meant with “making PDF may be the best way”? And not one pdf but thousands. The html is not simple html. Is printing from a html viewer into pdf now considered unsafe?

I am sorry, I can’t just create you a function. I can only look what Apple provides with WKWebView and related classes.
see
https://developer.apple.com/documentation/webkit/wkwebview

If there is a function in Apple’s framework, which we could expose in the plugin, we may be able to add it.

The documentation is depressing. What about the CacheModel?

Well, you may better try with private browsing, e.g. using nonPersistentDataStore.

I think we have a privateBrowsing property for that you can set before creating our plugin control.

PS: Schau mal aus dem Fenster. Ich fahre per IC gerade bei euch vorbei…