Print Page | Close Window

webbrowser control / printing

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Controls
Forum Description: Topics Related to Codejock Controls
URL: http://forum.codejock.com/forum_posts.asp?TID=14520
Printed Date: 05 May 2024 at 12:42am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: webbrowser control / printing
Posted By: fuxi
Subject: webbrowser control / printing
Date Posted: 12 June 2009 at 10:24am
hi all,

i managed to display + print data but here's my problem:

i'd like to do somekind of serial printing - the problem: printing gives me missing + blank pages.
i'm doing it like this:

for page=1 to 20
   with mybrowserWrapper
      .generate_page page ' i'm generating html data out of a database
      .show                          ' i'm now saving the html data to a tmpfile, loading it to the control using .navigate tmpfile
                                         ' the html appears, and i'm using Do While htm.Busy: DoEvents: Loop to determine when it has finished loading
      .printIt                        ' i'm printing like this: htm.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
   end with
next

the code seems ok, but there's something with printing, either the printing routine starts before it gets data (blank pages) or it's skipping pages (the loop continues before printing has finished).

i'm not sure where to find the problem :/ but i guess i need to wait until print has finished before i generate the next page.

anyone knows how to do it?
thanks,
fuxi



Replies:
Posted By: Krog
Date Posted: 27 June 2009 at 4:58am
Hi!

This is the way the WebBrowser control handles printing:

By default, the ExecWB() method passes a copy of the document to a separate thread, which then performs the actual printing. In this way the ExecWB() method returns immediately, without waiting for the thread to finish, and if the browser is destroyed while printing is still in progress, only part of the contents will be printed.

You can use the following constants:


Const PRINT_DONTBOTHERUSER = 1
Const PRINT_WAITFORCOMPLETION = 2


These can be used to enhance the print function. For example: PRINT_WAITFORCOMPLETION can be used to wait until the pages have been sent to the printer before continuing (especially useful if you want to restore the original header/footer) and PRINT_DONTBOTHERUSER can be used to hide all print dialogs.

So the code may look like this:


' start printing, and wait until output has been spooled to printer...
WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, PRINT_WAITFORCOMPLETION Or PRINT_DONTBOTHERUSER, 0


There is more info in the MSDN link bellow:

http://msdn.microsoft.com/en-us/library/aa769937(VS.85).aspx


-------------
Product: Xtreme SuitePro (ActiveX) version 15.2.1
Platform: Windows XP SP2
Language: Visual Basic 6 SP6



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net