Welcome Guest Search | Active Topics | Sign In | Register

Print Dialog - Not automatic even with BeforePrint Handler - HELP!!! Options
awesam
Posted: Friday, March 10, 2023 8:48:46 AM
Rank: Newbie
Groups: Member

Joined: 3/10/2023
Posts: 1
Hi,

I am trying to make a program to automatic print the website for a label.

Everything is working, EXCEPT that when the print dialog appears it does not automatically OK the print and therefore no print job is sent to the printer, it MUST be automatic

How can I do this?!

I tried from vb.net code and from javascript using window.print() and still getting the print dialog!!!!!

CODE:
=======

Public Sub PrintBoxLabel()

'// Load pallet to be printed in webbrowser
WebControl1.WebView.Url = "http://192.168.1.1/boxlabel.php?ID=1000"

'// print.
'Get the default print settings
Dim settings As Printing.PrinterSettings = WebView.GetDefaultPrinterSettings()

AddHandler WebView1.BeforePrint, New BeforePrintHandler(AddressOf webView1_BeforePrint)

'Start printing with the above settings
WebView1.Print(settings)

End If

End Sub

Private Sub webView1_BeforePrint(sender As Object, e As BeforePrintEventArgs)

e.Continue(False)

End Sub
eo_support
Posted: Friday, March 10, 2023 11:08:25 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

Your code looks correct. Except that you probably do not want to call AddHandler every time you call PrintBoxLabel. The event handler should only be called once so you may want to call it beforehand (for example, in Form_Load if you use Windows.Forms).

If you continue to have problem, please try to isolate the problem into a test project and send the test project to us:

https://www.essentialobjects.com/forum/test_project.aspx

We will look into it once we have that.

Thanks!
eo_support
Posted: Sunday, March 12, 2023 1:44:31 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

We have looked into your sample project. There are a number of issues with your code. The most important issue is you have two WebView objects in your project: WebView1 and WebView2. You are loading your Url into WebView2 (WebControl1.WebView is assigned to WebView2), but you are calling Print on WebView1. So you will need to fix that first.

The second issue you have is you can not call Print immediately after setting WebView.Url because loading the page is not instant. You need to wait until the Url finishes loading first before you can call Print.

The third issue is you can not trigger these kind of tasks with a timer. Because loading a Url and printing a page takes time and it can take different amount of time during each iteration, you will need to wait for each step to finish before you start another step. The easiest way for you to do this is to use async feature. For example, the following code demonstrates how to load and print 10 pages one after another:

Code: Visual Basic.NET
Private Async Sub LoadAndPrint10Pages(ByVal webView As WebView)
    For i As Integer = 1 To 10
        'You may need to have some kind of mechanism to exit this
        'For loop half way. For example, User may want to close your
        'application only after 5 print tasks, to handle that situation
        'you may need to set a flag when user closes the form and then
        'check that flag here so that you can exit the for loop early
        If ShouldStop() Then Exit For

        'Load and wait for the page to finish loading
        Await webView.LoadUrlAsync(pageUrl & "?page=" & i.ToString())

        'Start print and wait for the printing job is sent to the printer queue
        Await webView.PrintAsync()
    Next
End Sub


Note that you must reference EO.Extensions.dll and also use .NET 4.6 and above in order to use the async feature.

Hope this helps. Please feel free to let us know if you have any more questions.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.