WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Printing Information

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Print Graphic UDF


Question:

I am new to this app, and want to know if it is appropriate to my needs. My environment contains win2k servers, 98se, me, 2k and xp clients (i use citrix to deal with the macs). I am installing a new CRM software, and want to automate printing of jpegs for my salesmen (so they can accomplish it unaided). to do this i need to NOT use the print window from windows. I want to be able to pass in filename and potentially quantity of copies...

Can I do this with this product? There will only be one printer, which is on the network, and is a Xerox XP12 Fiery- and is accessible to all clients.

Answer:

Here is some code I threw together that can print a graphic file, to the default printer, using Internet Explorers WebBrowser Objects.

NOTE: Internet Explorer 4.0 supports both OLECMDEXECOPT_PROMPTUSER and OLECMDEXECOPT_DONTPROMPTUSER. However, OLECMDID_DONTPROMPTUSER is ignored in Internet Explorer 5, because printing is considered to be a security issue, A Web page should not have the ability to start a print job without confirmation from the user. In Internet Explorer 5.5 and later, the print job is completed without user confirmation.

#DefineFunction PrintGraphic(File)
   ;This can be used to Print:
	;HTML files 
	;Graphics files (i.e., BMP TIFF JPG JPEG GIF)
	; Requires Windows 2000 or later.
	if WinVersion(1) != 5
	    Message("Error","This function is not supported on this Windows platform")
		 return(0)
	endif
	objBrowser = objectopen("InternetExplorer.Application")
	objBrowser.addressbar = @false
	objBrowser.statusbar = @false
	objBrowser.menubar = @false
	objBrowser.toolbar = @false
	objBrowser.visible = @false
	objBrowser.navigate(file)
	While @true
	   If objBrowser.ReadyState == 4 then Break
	   TimeDelay(1)
	EndWhile
	objBrowserDoc = objBrowser.Document
	objAll = objBrowserdoc.all
	
	;http://msdn.microsoft.com/library/en-us/com/htm/oen_a2z_22sk.asp?frame=true
	OLECMDID_PRINT = 6
	
	;http://msdn.microsoft.com/library/en-us/com/htm/oen_a2z_5k38.asp?frame=true
	OLECMDEXECOPT_DONTPROMPTUSER  = 2
	
	;http://msdn.microsoft.com/workshop/browser/mshtml/reference/constants/idm_print.asp
	PRINT_DONTBOTHERUSER = 1
	PRINT_WAITFORCOMPLETION = 2
	pvaIn = ObjectType("I2",PRINT_WAITFORCOMPLETION|PRINT_DONTBOTHERUSER)
	pvaOut = ObjectType("NULL","")
	
	;http://msdn.microsoft.com/workshop/browser/webbrowser/reference/ifaces/iwebbrowser2/execwb.asp?frame=true
	objBrowser.ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER,pvaIn, pvaOut)
	
	;Give the browser enough time to print before closing the object
	TimeDelay(1)
	
	ObjectClose(objBrowserDoc)
	ObjectClose(objAll)
	ObjectClose(objBrowser)
	Return(1)
#EndFunction

file = "c:\temp\test.jpg"
PrintGraphic(File)
Exit

Article ID:   W16168
File Created: 2004:03:30:15:43:04
Last Updated: 2004:03:30:15:43:04