Introduction
The Print Wizard engine can easily be embedded and used from your own scripts and applications with little effort. You can actually fire off the engine directly with command-line parameters. You can also use the printwiz.dll or the WēPO ActiveX module from your application, or you can “start” a print file that has a registered file extension association that will always print with the Print Wizard engine.
Print Wizard will run quietly to avoid any interaction and hence run completely hidden from the end-user, or you can run interactively in order to see what is happening. Either way, Print Wizard will still return an error code that can be checked by the parent program or through the script to handle errors properly.
Print Wizard can be your all-in-one printing solution for your needs without having to worry about fit-to-page, handling overlays and remaining printer-independent in all aspects of your printing.
Using the Print Wizard Engine
Most application programming languages do support starting an external program from within the parent environment. Even Shell scripts and Windows management scripting languages support calls to start an external program.
Print Wizard, with its many command-line options, make it possible to run the Print Wizard engine to do exactly what you wish. Here is a typical code snippet showing an example of starting Print Wizard from a Delphi program and handling the results properly:
// Write my data to an output file
……………
// CreateProcess Stuff
fillchar(startupinfo, sizeof(startupinfo), 0);
startupinfo.cb := sizeof(startupinfo);
startupinfo.wShowWindow := SW_MINIMIZE;
startupinfo.dwFlags := STARTF_USESHOWWINDOW;
flags := 0;
params := '/pdf://' + myfilename + ' ' + myfilename;
spCommand := 'C:\Program Files\PrintWiz\printwiz.exe' + ' ' + params;
if not CreateProcess(nil, @spCommand[1], nil, nil, false, flags, nil,
nil, StartupInfo, ProcessInfo) then
ShowMessage('Print Wizard failed to start: ' + spCommand + ' ' +
Myfilename)
else
begin
// wait for completion
process := ProcessInfo.hProcess;
while true do
begin
Application.ProcessMessages;
if GetExitCodeProcess(Process, ReturnCode) then
begin
if Returncode = STILL_ACTIVE then
sleep(500)
else
begin
if ReturnCode > 0 then
HandleReturn(ReturnCode)
else
Result := true;
break;
end;
end
else
begin
Result := true;
break;
end;
end;
end;
The following is an example of running Print Wizard to process a file through a Windows script:
' Generate my data to a file
…………
' Run Print Wizard against that file
set shell = CreateObject("WScript.Shell")
for each filename in WScript.arguments
'Process each command-line filename
set pw = shell.Exec("c:\printwiz\printwiz.exe /q /preview " +
filename)do while pw.status = 0
WScript.echo "Print Wizard processing, processid is ", pw.processid ' current process id
WScript.sleep 100
loopWScript.echo "Print Wizard complete for file " + filename
WScript.echo " return code", pw.exitcode ' PW Halt CodeNext
Using the Print Wizard DLL
Like the above, the printwiz.dll can be used from most any application by simply programming for access to the Print Wizard DLL. This is a standard Windows dynamic linked library, supporting some basic calls for handling printing.
Please refer to the Print Wizard manual or the various support documents and examples on the PrintWiz.DLL for more information.
Using the ActiveX Web Print Object - WēPO
From a web page called by the browser, a web service, an ASP or ASP.NET program, from a third party application, or from your own Windows or .NET application, you can include code to handle the Print Wizard ActiveX module called WēPO. WēPO provides programmers a way to “pull” print jobs from a file server, web server or FTP site, and “push” them to a user’s local printer.
WēPO accomplishes this with a standard Windows ActiveX module,
PWButtonXControl1.ocx
This ActiveX module behaves similar to the printwiz.dll and exposes much of the functionality of Print Wizard to your application. Please refer to the Print Wizard manual or the various support documents and examples on WēPO for more information.
Starting a File Association
Print Wizard can also be set up as the default print handler for any file extension through either the Print Wizard user interface or through the File Type options of Windows Explorer (within Windows Explorer on Windows XP, go to the Tools : Folder Options : File Types dialog). Through either of these methods, you can set Windows up to always print a specific file type (file extension or association) through the Print Wizard engine.
A simple example would be an application creates a print job with the file named mytestfile.prn, which we want to print through Print Wizard. The Windows file association can be set to print this particular extension, ‘.prn’, through Print Wizard for either drag and drop use inside Windows Explorer, or for file execution when Windows is told to print it, as is shown in this code snippet from a Delphi program:
if FileExists('myprintfile.prn') then
begin
spCommand := 'myprintfile.prn';
i := ShellExecute(0, 'print', @spCommand[1], nil, nil,
SW_SHOWMINIMIZED);
if i > 32 then // did not start OK
ShowMessage('Unable to print myprintfile.prn');
end;
Return Codes and Errors
Whenever you run Print Wizard from another program and in “quiet” mode (command-line switch of “/q”), Print Wizard will issue a return code upon completion stating whether it was successful in processing the file you sent. A complete list of return codes possible from the Print Wizard engine can be found in the Print Wizard Error Codes document or in the most recent Print Wizard manual.
A very simple example of running the Print Wizard engine from a Windows script is shown below:
‘ Run this from Cmd as wscript xxxxxx.vbs for dialog messages
‘ or cscript xxxx.vbs for console messagesset shell = CreateObject("WScript.Shell")
for each filename in WScript.arguments
‘Process each command-line filenameset pw = shell.Exec("c:\printwiz30\printwiz.exe /q " + filename)
do while pw.status = 0
WScript.echo "Print Wizard processing, processid is ", pw.processid
‘ current process id
WScript.sleep 100
LoopWScript.echo "Print Wizard complete for file " + filename
WScript.echo " return code", pw.exitcode ‘ PW Halt Code
WScript.echo " program status code ", pw.status
‘ PW status (0 running, 1-terminated)next