The export can be HTML, TEXT and PDF, all at the same time. The user is already presented with a āSelectFolderā-dialog to store the output files in, and then also a print-dialog in between is a bit weird.
The last stable series is 0.12.6, which was released on June 11, 2020
Update: Reading the License file shows that anyone who uses the library must make available āCorresponding Application Codeā. I am not a lawyer, but in spirit that means if you use the library, whether you want to or not, your app automatically becomes open source. Kind of the gotcha for LGPL that makes commercial developers wary of such libraries.
The html needs to be loaded into an html viewer which is annoying to do in a thread. There are sometimes errors from macOS (that was āError when printingā). Itās a 2 step process which is also annoying. There are really odd problems like the html saying 2 times it was printed. There are other problems. And finally itās slow.
@Christian_Schmitz Thanks for the tip! Currently itās for Mac only. Got it working!
Dim w As WKWebViewMBS = Window1.HTMLViewer1.WKWebViewMBS
Dim pi As NSPrintInfoMBS = NSPrintInfoMBS.sharedPrintInfo
pi.SetSaveDestination(f)
pi.horizontalPagination = pi.NSAutoPagination
pi.verticalPagination = pi.NSAutoPagination
pi.topMargin = 28
pi.rightMargin = 28
pi.bottomMargin = 28
pi.leftMargin = 28
Dim po As NSPrintOperationMBS = w.printOperation(pi)
po.showsPrintPanel = False
po.showsProgressPanel = False
po.runOperationModalForWindow(Self)
where f is pre-created FolderItem for the outputfile.
@Christian_Schmitz Now Iām trying to run this in the background and process multiple selected rows from a listbox. This means I cannot update the HTMLviewer while looping through the the selected rows, so I want to load the HTML directly into the WKWebViewMBS and then output that to PDF.
But I get a NilObjectException when I do this:
Dim w As WKWebViewMBS
w.LoadHTML(s)
where s is a string containing some HTML code, like <table><tr><td>⦠etc..
What can that be?
And when I do this:
Dim w As WKWebViewMBS = Window1.HTMLViewer1.WKWebViewMBS
w.LoadHTML(s)
I do not get an error, but a PDF with empty pages, which suggests that it knows the size, but it doesnāt output the contents.
Public Sub SetHtml(hasHtml as String, hasUUID as String)
theHtml = hasHtml
if not HasPrintStyles then EnsurePrintCSS
'EnsureReadyMarker
UUID = hasUUID
PrintCounter = 0
dim thePrefs as new WKPreferencesMBS(WKWebViewControlMBS1.WKWebView)
#Pragma BreakOnExceptions False
try
thePrefs.crossOriginResourcePolicyEnabled = True
WKWebViewControlMBS1.WKWebView.Configuration.limitsNavigationsToAppBoundDomains = True
catch err as NSExceptionMBS
'ignore, not available on bug sir
end try
#Pragma BreakOnExceptions True
if Thread.Current <> nil then
HtmlTimer.RunMode = Timer.RunModes.Single
else
WKWebViewControlMBS1.LoadHTML(theHtml, āā)
end if
DocumentTimer.RunMode = Timer.RunModes.Single
End Sub
Load the html:
Sub Action() Handles Action
Globals.theErrorLog.LogitemToConsole(currentMethodName + " 1")
WKWebViewControlMBS1.LoadHTML(theHtml, āā)
HtmlTimer.RunMode = Timer.RunModes.Off
Globals.theErrorLog.LogitemToConsole(currentMethodName + " 2")
End Sub
Html was loaded:
Sub didFinishNavigation(navigation as WKNavigationMBS) Handles didFinishNavigation
#Pragma Unused navigation
Globals.theErrorLog.LogitemToConsole(currentMethodName + " 1")
'as soon as the html viewer has loaded data it can be printed
DocumentTimer.RunMode = Timer.RunModes.Off
me.EvaluateJavaScript(BlockQuoteCSSScript)
TempItem = Nil
'duplicate
if theHtml = āā then
Break
Return
end if
Print
Globals.theErrorLog.LogitemToConsole(currentMethodName + " 2")
End Sub
And then the html can be printed in the print method.
Ok, so I find this is not doable for looping through many selected rows of a listbox - way to complex for me with timers and such. Iāll allow PDF output only when just 1 row is selected.