B4J Question [SOLVED] Print from webview

jroriz

Active Member
Licensed User
Longtime User
A friend asked me to create a desktop application for him based on his website.

The webview would be perfect, but it does not open links in new windows, and that would be mandatory, especially in print routines.

Is there a workaround for this?

Use this page to test:
WebView1.Loadurl ("https://sisweb.app/test")

This page has only one button with onclick = "window.print ()"
 

jroriz

Active Member
Licensed User
Longtime User
The best you can do is to handle the LocationChanged event and get the URL. You can then revert back to the previous URL.
Well, I was able to detect the page following your guidance.

My first idea was to send the page to the browser to print (fx.ShowExternalDocument), but there needs to be an open session, so the browser asks for a username and password.

The webview correctly renders what needs to be printed.
So I tried to print the content using JavaFX8 (I printed the webview), but the result was terrible.

Would it be possible to capture the rendered html in the webview and then use the printhtml to print?
 
Upvote 0

jroriz

Active Member
Licensed User
Longtime User
Solved.
Removed session validation from page.
Downloaded the page and printed with printhtml.
 
Upvote 0
Top