Skip to main content

Using the Print Wizard DLL

Introduction

The Print Wizard DLL is Windows dynamic link library that can be called from any other program to perform certain Print Wizard functions. Most anything you can do with the Print Wizard engine, can also be called through the Print Wizard DLL.

The basic concept here is to configure the printer or set the printer name to a specific printer, print the file or the lines of text you wish and then flush the printer to close the print job. If you do not specify a printer (using either the “pw_set_printer” or the “pw_configure_printer”) then the default printer will be used.

The various procedures are shown below (these may change and be added to over time, if something does not work or you need additional capabilities, contact us):

Procedure

Return

Description

pw_configure_printer(hwnd : handle):longint

Returns 1 if successful, else 0

Bring up the Windows standard “printer setup” dialog.

pw_set_printer(p : pchar)

None

Set the printer to the provided name.

pw_print_text(p : pchar; count : longint; cs : longint):longint

Returns 1 if successful, else 0

Print the text where “cs” is
   0 for ISO
   1 for OEM
   2 for other (no translation)
   3 for Unicode UTF-8
Count is the size of the text string to print.

pw_print_text_w(p : pwidechar; count : longint):longint

Returns 1 if successful, else 0

Print the string of text as wide Unicode characters. Count is the size of the text string to print.

pw_flush

None

Flush and end the print job.

pw_set_html_base(p : pchar)

None

Set the HTML base. This is the default directory used when an image file or other files are referenced by relative path (as defined in the HTML standards).

pw_set_preview(b : longint)

None

Set to 1 to preview print jobs and 0 to print them.

pw_set_orientation(b : longint)

None

Set to 0 for portrait, 1 for landscape and 2 for “auto” (automatically adjust orientation for text line lengths).

pw_set_font(p : pchar)

None

Set the name of the font to use.

pw_set_overlay(p : pchar)

None

Set the name of the overlay file.

pw_set_copies(n : longint)

None

Set the number of copies.

pw_print_emf(h : handle)

None

Set the EMF to print.

pw_eject_page

None

Eject the page.

pw_set_output(p : pchar; count : longint):longint

Returns 1 if successful, else 0

Set the file name to print to. Count is the size of the file name string.

pw_print_file(p : pchar; count : longint; cs : longint):longint

Returns 1 if successful, else 0

Set the name of the file to print. Count is the size of the file name and cs is the character set as described above.

pw_get_printer:variantstring

Returns the name of the printer or blanks if set to the PC default printer.

Get the name of the printer that is being used.

pw_get_version:variantstring

Returns a string representing the version of Print Wizard’s DLL.

Get the version of Print Wizard as a string, i.e. “3.0”.

pw_translate_pcl(n : longint)

none

Set to 0 for no translation; to 1 for translation of main file and overlay; to 2 for translation of main file only.

pw_device_caps(n : longint)

Returns the requested measurement page

Gets a measurement of the printer page.  Passed value "n" indicates which measurement.  Common examples are:
   8 for horizontal width in pixels
   10 for vertical height in pixels
   12 for color bits per pixel
   14 for number of color planes
   88 for logical pixels per inch in horizontal
   90 for logical pixels per inch in vertical
   110 for physical width of page, in pixels
   111 for physical height of page, in pixels
   112 for horizontal unprintable offset, in pixels
   113 for vertical unprintable offset, in pixels
Other values are also possible, as documented for Windows call GetDeviceCaps.

pw_measure_text_w(p : pwidechar; ct : longint)

Returns the width of the text, in pixels

For the current active font and other printing environment, tells the width of the indicated text, which must be in widechars.

Print Wizard DLL Examples

Like the Print Wizard engine, the Print Wizard DLL is usable from within any 3rd party program that supports calls to Windows style DLL modules. The Print Wizard DLL supplies these programs with direct control of printed output via the DLL calls, and includes support for all the Print Wizard features discussed elsewhere in this manual.

Visual Basic Example

There are many exposed functions of the Print Wizard DLL. The first box below shows some of those functions, followed by a short example utilizing them. Likewise, this can be done through many other languages as well (see our included examples and other examples at our web site).

Private Declare Function pw_configure_printer Lib "pwdll" (ByVal window As
        _ Integer) As Long
        'returns 1 if successful, else 0
Private Declare Sub pw_set_printer Lib "pwdll" (ByVal lpchar As String)
        'set printer by name
Private Declare Function pw_print_text Lib "pwdll" (ByVal lpchar As String, _
        ByVal count As Long, ByVal cs As Long) As Long
        'returns 1 if successful, else 0
        'cs is 0 for ISO
        '      1 for OEM
        '      2 for other (no translation)
        '      3 for Unicode UTF-8'
''WIDE VERSION ###
Private Declare Sub pw_flush Lib "pwdll" ()
        'terminates print job
Private Declare Sub pw_set_html_base Lib "pwdll" (ByVal lpchar As String)
        'sets the html_base for relative filenames
Private Declare Sub pw_set_preview Lib "pwdll" (ByVal b As Long)
        'b is 1 for preview on
        '     0 for preview off
Private Declare Sub pw_set_orientation Lib "pwdll" (ByVal b As Long)
        'b is 0 for portrait
        '     1 for landscape
        '     2 for auto
Private Declare Sub pw_set_font Lib "pwdll" (ByVal lpchar As String)
        'specify font name(s)
Private Declare Sub pw_set_overlay Lib "pwdll" (ByVal lpchar As String)
        'specify name of overlay
Private Declare Sub pw_set_copies Lib "pwdll" (ByVal n As Long)
        'set number of copies
Private Declare Sub pw_eject_page Lib "pwdll" ()
        'equivalent to printing a formfeed
Private Declare Function pw_set_output Lib "pwdll" (ByVal lpchar As String, _
        ByVal count As Long) As Integer
        'returns 1 if successful, else 0
        'sets type of output
        '   empty string for printing
        '   PDF://              Generate PDF file with default name
        '   PDF://    Generate PDF file with given name
        '   FAX32://  Send fax
Private Declare Function pw_print_file Lib "pwdll" (ByVal lpchar As String, _
        ByVal count As Long, _
        ByVal cs As Long) As Integer
        'prints an entire file
        'returns 1 if successful
        'cs is charset as above

This example is for a button that when clicked will create a PDF file through the Print Wizard DLL.

Private Sub Command1_Click()
   ct = Len(Text2.Text)
   pw_set_orientation (1)                             ‘ landscape  
   res = pw_print_text(Text2.Text, ct, 0)
   If res 0 Then
      pw_flush
   End If
   If res = 0 Then
      MsgBox ("Function failed")
   End If
End Sub

 

Delphi Example


function pw_configure_printer(hwnd : THandle) : longint; stdcall;
   external 'pwdll.dll' name 'pw_configure_printer';
function pw_print_file(p : pchar; ct : longint; cs : longint):longint;stdcall;
   external 'pwdll.dll' name 'pw_print_file';
function pw_set_output(p : pchar; ct : longint):longint; stdcall;
   external 'pwdll.dll' name 'pw_set_output';
procedure pw_set_copies(n : longint);stdcall;
   external 'pwdll.dll' name 'pw_set_copies';
function pw_print_text(p : pchar; count : longint; cs : longint):longint;stdcall;
   external 'pwdll.dll' name 'pw_print_text';
function pw_print_text_w(p : pwidechar; count : longint):longint;stdcall;
   external 'pwdll.dll' name 'pw_print_text_w';
procedure pw_flush; stdcall;
   external 'pwdll.dll' name 'pw_flush';
function pw_get_printer:OleVariant;safecall;
   external 'pwdll.dll' name 'pw_get_printer';
function pw_get_version:OleVariant;safecall;
   external 'pwdll.dll' name 'pw_get_version';

var
   filename : ansistring;
   output   : ansistring;
   i        : integer;
   s        : string;
begin
   // Check file name
   filename := paramstr(1);
   if not FileExists(filename) then
     begin
       Writeln('File not found');
       Readln;
       exit;
     end;

   // Ask for a printer name
   s := pw_get_printer;
   i := pw_configure_printer(0);
   if i = 0 then
     begin
       Writeln('Configure printer failed');
       Readln;
       exit;
     end;
   s := pw_get_printer;

   // Check to see if we are writing to a file
   output := paramstr(2);
   if output '' then
     i := pw_set_output(pchar(output), length(output));

   // Wiz print text
   s := 'This is printed with the test program';
   i := pw_print_text(pchar(s), length(s), 0);

   // Others
   pw_set_copies(2);
   // Get printer name and version. Configure_printer will set this.
   // If you do not do Configure_printer sometime earlier, this is left blank
   // to print to the default printer.
   s := pw_get_printer;
   writeln(s);
   s := pw_get_version;
   writeln(s);

   // Print a file
   i := pw_print_file(pchar(filename), length(filename), 1);

   // End this print job
   if i 0 then
     pw_flush;

end.

Copyright © 2020 Rasmussen Software, Inc. Legal Information & Privacy Policy
Send comments and suggestions to rsi@anzio.com