Printer functions
Printer
These functions are only available under Windows 9.x, ME, NT4 and
2000. They have been added in PHP 4 (4.0.4).
printer_open
Open connection to a printer
Description
mixedprinter_open
stringdevicename
This function tries to open a connection to the printer
devicename, and returns a handle on success
or &false; on failure.
If no parameter was given it tries to open a
connection to the default printer (if not specified in
&php.ini; as
printer.default_printer, php tries to detect it).
printer_open also starts a device context.
printer_open example
printer_abort
Deletes the printer's spool file
Description
voidprinter_abort
resourcehandle
This function deletes the printers spool file.
handle must be a valid handle to a printer.
printer_abort example
printer_close
Close an open printer connection
Description
voidprinter_close
resourcehandle
This function closes the printer connection.
printer_close also closes the active device
context.
handle must be a valid handle to a printer.
printer_close example
printer_write
Write data to the printer
Description
boolprinter_write
resourcehandle
stringcontent
Writes content directly to the printer, and
returns &true; on success or &false; if it failed.
handle must be a valid handle to a printer.
printer_write example
printer_list
Return an array of printers attached to the server
Description
arrayprinter_list
intenumtype
stringname
intlevel
The function enumerates available printers and their capabilities.
level sets the level of information request.
Can be 1,2,4 or 5. enumtype must be one of the
following predefined constants:
PRINTER_ENUM_LOCAL:
enumerates the locally installed printers.
PRINTER_ENUM_NAME:
enumerates the printer of name, can be a server,
domain or print provider.
PRINTER_ENUM_SHARED:
this parameter can't be used alone, it has to be OR'ed with other
parameters, i.e. PRINTER_ENUM_LOCAL to detect the locally shared
printers.
PRINTER_ENUM_DEFAULT:
(Win9.x only) enumerates the default printer.
PRINTER_ENUM_CONNECTIONS:
(WinNT/2000 only) enumerates the printers to which the user has
made connections.
PRINTER_ENUM_NETWORK:
(WinNT/2000 only) enumerates network printers in the computer's
domain. Only valid if level is 1.
PRINTER_ENUM_REMOTE:
(WinNT/2000 only) enumerates network printers and print servers in the
computer's domain. Only valid if level is 1.
printer_list example
printer_set_option
Configure the printer connection
Description
boolprinter_set_option
resourcehandle
intoption
mixedvalue
The function sets the following options for the current connection:
handle must be a valid handle to a printer.
For option can be one of the following constants:
PRINTER_COPIES:
sets how many copies should be printed, value
must be an integer.
PRINTER_MODE:
specifies the type of data (text, raw or emf),
value must be a string.
PRINTER_TITLE:
specifies the name of the document, value
must be a string.
PRINTER_ORIENTATION:
specifies the orientation of the paper, value
can be either PRINTER_ORIENTATION_PORTRAIT or
PRINTER_ORIENTATION_LANDSCAPE
PRINTER_RESOLUTION_Y:
specifies the y-resolution in DPI, value
must be an integer.
PRINTER_RESOLUTION_X:
specifies the x-resolution in DPI, value
must be an integer.
PRINTER_PAPER_FORMAT:
specifies the a predefined paper format, set value
to PRINTER_FORMAT_CUSTOM if you want to specify a custom format with
PRINTER_PAPER_WIDTH and PRINTER_PAPER_LENGTH. value
can be one of the following constants.
PRINTER_FORMAT_CUSTOM:
let's you specify a custom paper format.
PRINTER_FORMAT_LETTER:
specifies standard letter format (8 1/2- by 11-inches).
PRINTER_FORMAT_LETTER:
specifies standard legal format (8 1/2- by 14-inches).
PRINTER_FORMAT_A3:
specifies standard A3 format (297- by 420-millimeters).
PRINTER_FORMAT_A4:
specifies standard A4 format (210- by 297-millimeters).
PRINTER_FORMAT_A5:
specifies standard A5 format (148- by 210-millimeters).
PRINTER_FORMAT_B4:
specifies standard B4 format (250- by 354-millimeters).
PRINTER_FORMAT_B5:
specifies standard B5 format (182- by 257-millimeter).
PRINTER_FORMAT_FOLIO:
specifies standard FOLIO format (8 1/2- by 13-inch).
PRINTER_PAPER_LENGTH:
if PRINTER_PAPER_FORMAT is set to PRINTER_FORMAT_CUSTOM,
PRINTER_PAPER_LENGTH specifies a custom paper length in mm,
value must be an integer.
PRINTER_PAPER_WIDTH:
if PRINTER_PAPER_FORMAT is set to PRINTER_FORMAT_CUSTOM,
PRINTER_PAPER_WIDTH specifies a custom paper width in mm,
value must be an integer.
PRINTER_SCALE:
specifies the factor by which the printed output is to be scaled.
the page size is scaled from the physical page size by a factor
of scale/100. for example if you set the scale to 50, the output
would be half of it's original size. value
must be an integer.
PRINTER_BACKGROUND_COLOR:
specifies the background color for the actual device context,
value must be a string containing the rgb
information in hex format i.e. "005533".
PRINTER_TEXT_COLOR:
specifies the text color for the actual device context,
value must be a string containing the rgb
information in hex format i.e. "005533".
PRINTER_TEXT_ALIGN:
specifies the text alignment for the actual device context,
value can be combined through OR'ing the
following constants:
PRINTER_TA_BASELINE:
text will be aligned at the base line.
PRINTER_TA_BOTTOM:
text will be aligned at the bottom.
PRINTER_TA_TOP:
text will be aligned at the top.
PRINTER_TA_CENTER:
text will be aligned at the center.
PRINTER_TA_LEFT:
text will be aligned at the left.
PRINTER_TA_RIGHT:
text will be aligned at the right.
printer_set_option example
printer_get_option
Retrieve printer configuration data
Description
mixedprinter_get_option
resourcehandle
stringoption
The function retrieves the configuration setting of option.
handle must be a valid handle to a printer.
Take a look at printer_set_option for the settings that can
be retrieved, additionally the following settings can be retrieved:
PRINTER_DEVICENAME
returns the devicename of the printer.
PRINTER_DRIVERVERSION
returns the printer driver version.
printer_get_option example
printer_create_dc
Create a new device context
Description
voidprinter_create_dc
resourcehandle
The function creates a new device context. A device context is used
to customize the graphic objects of the document.
handle must be a valid handle to a printer.
printer_create_dc example
printer_delete_dc
Delete a device context
Description
boolprinter_delete_dc
resourcehandle
The function deletes the device context and returns &true; on success,
or &false; if an error occurred. For an example see
printer_create_dc. handle
must be a valid handle to a printer.
printer_start_doc
Start a new document
Description
boolprinter_start_doc
resourcehandle
stringdocument
The function creates a new document in the printer spooler. A document
can contain multiple pages, it's used to schedule the print job in the
spooler. handle must be a valid handle to a
printer. The optional parameter document can be
used to set an alternative document name.
printer_start_doc example
printer_end_doc
Close document
Description
boolprinter_end_doc
resourcehandle
Closes a new document in the printer spooler. The document
is now ready for printing. For an example see
printer_start_doc.
handle must be a valid handle to a printer.
printer_start_page
Start a new page
Description
boolprinter_start_page
resourcehandle
The function creates a new page in the active document. For an
example see printer_start_doc.
handle must be a valid handle to a printer.
printer_end_page
Close active page
Description
boolprinter_end_page
resourcehandle
The function closes the active page in the active document. For an
example see printer_start_doc.
handle must be a valid handle to a printer.
printer_create_pen
Create a new pen
Description
mixedprinter_create_pen
intstyle
intwidth
stringcolor
The function creates a new pen and returns a handle to it. A pen is
used to draw lines and curves. For an example see
printer_select_pen. color
must be a color in RGB hex format, i.e. "000000" for black,
width specifies the width of the pen whereas
style must be one of the following constants:
PRINTER_PEN_SOLID:
creates a solid pen.
PRINTER_PEN_DASH:
creates a dashed pen.
PRINTER_PEN_DOT:
creates a dotted pen.
PRINTER_PEN_DASHDOT:
creates a pen with dashes and dots.
PRINTER_PEN_DASHDOTDOT:
creates a pen with dashes and double dots.
PRINTER_PEN_INVISIBLE:
creates an invisible pen.
printer_delete_pen
Delete a pen
Description
boolprinter_delete_pen
resourcehandle
The function deletes the selected pen. For an example see
printer_select_pen. It returns &true; on success,
or &false; otherwise. handle must be a valid
handle to a pen.
printer_select_pen
Select a pen
Description
voidprinter_select_pen
resourceprinter_handle
resourcepen_handle
The function selects a pen as the active drawing object of the actual
device context. A pen is used to draw lines and curves. I.e. if you draw
a single line the pen is used. If you draw an rectangle the pen is used
to draw the borders, while the brush is used to fill the shape.
If you haven't selected a pen before drawing shapes, the shape won't be
outlined. printer_handle must be a valid handle
to a printer. pen_handle must be a valid handle
to a pen.
printer_select_pen example
printer_create_brush
Create a new brush
Description
mixedprinter_create_brush
intstyle
stringcolor
The function creates a new brush and returns a handle to it. A brush
is used to fill shapes. For an example see
printer_select_brush. color
must be a color in RGB hex format, i.e. "000000" for black,
style must be one of the following constants:
PRINTER_BRUSH_SOLID:
creates a brush with a solid color.
PRINTER_BRUSH_DIAGONAL:
creates a brush with a 45-degree upward left-to-right hatch ( / ).
PRINTER_BRUSH_CROSS:
creates a brush with a cross hatch ( + ).
PRINTER_BRUSH_DIAGCROSS:
creates a brush with a 45 cross hatch ( x ).
PRINTER_BRUSH_FDIAGONAL:
creates a brush with a 45-degree downward left-to-right hatch ( \ ).
PRINTER_BRUSH_HORIZONTAL:
creates a brush with a horizontal hatch ( - ).
PRINTER_BRUSH_VERTICAL:
creates a brush with a vertical hatch ( | ).
PRINTER_BRUSH_CUSTOM:
creates a custom brush from an BMP file. The second parameter
is used to specify the BMP instead of the RGB color code.
printer_delete_brush
Delete a brush
Description
boolprinter_delete_brush
resourcehandle
The function deletes the selected brush. For an example see
printer_select_brush. It returns &true; on
success, or &false; otherwise. handle
must be a valid handle to a brush.
printer_select_brush
Select a brush
Description
voidprinter_select_brush
resourceprinter_handle
resourcebrush_handle
The function selects a brush as the active drawing object of the actual
device context. A brush is used to fill shapes. If you draw an rectangle
the brush is used to draw the shapes, while the pen is used to draw the
border.
If you haven't selected a brush before drawing shapes, the shape won't
be filled. printer_handle must be a valid handle
to a printer. brush_handle must be a valid handle
to a brush.
printer_select_brush example
printer_create_font
Create a new font
Description
mixedprinter_create_font
stringface
intheight
intwidth
intfont_weight
boolitalic
boolunderline
boolstrikeout
intorientaton
The function creates a new font and returns a handle to it. A font is
used to draw text. For an example see
printer_select_font. face
must be a string specifying the font face. height
specifies the font height, and width the font
width. The font_weight specifies the font weight
(400 is normal), and can be one of the following predefined constants.
PRINTER_FW_THIN:
sets the font weight to thin (100).
PRINTER_FW_ULTRALIGHT:
sets the font weight to ultra light (200).
PRINTER_FW_LIGHT:
sets the font weight to light (300).
PRINTER_FW_NORMAL:
sets the font weight to normal (400).
PRINTER_FW_MEDIUM:
sets the font weight to medium (500).
PRINTER_FW_BOLD:
sets the font weight to bold (700).
PRINTER_FW_ULTRABOLD:
sets the font weight to ultra bold (800).
PRINTER_FW_HEAVY:
sets the font weight to heavy (900).
italic can be &true; or &false;,
and sets whether the font should be italic.
underline can be &true; or &false;,
and sets whether the font should be underlined.
strikeout can be &true; or &false;,
and sets whether the font should be striked out.
orientation specifies a rotation.
For an example see printer_select_font.
printer_delete_font
Delete a font
Description
boolprinter_delete_font
resourcehandle
The function deletes the selected font. For an example see
printer_select_font. It returns &true; on success,
or &false; otherwise. handle must be a valid
handle to a font.
printer_select_font
Select a font
Description
voidprinter_select_font
resourceprinter_handle
resourcefont_handle
The function selects a font to draw text.
printer_handle must be a valid handle to a
printer. font_handle must be a valid handle
to a font.
printer_select_font example
printer_logical_fontheight
Get logical font height
Description
intprinter_logical_fontheight
resourcehandle
intheight
The function calculates the logical font height of
height. handle must
be a valid handle to a printer.
printer_logical_fontheight example
printer_draw_roundrect
Draw a rectangle with rounded corners
Description
voidprinter_draw_roundrect
resourcehandle
intul_x
intul_y
intlr_x
intlr_y
intwidth
intheight
The function simply draws a rectangle with rounded corners.
handle must be a valid handle to a printer.
ul_x is the upper left x coordinate of the rectangle.
ul_y is the upper left y coordinate of the rectangle.
lr_x is the lower right x coordinate of the rectangle.
lr_y is the lower right y coordinate of the rectangle.
width is the width of the ellipse.
height is the height of the ellipse.
printer_draw_roundrect example
printer_draw_rectangle
Draw a rectangle
Description
voidprinter_draw_rectangle
resourcehandle
intul_x
intul_y
intlr_x
intlr_y
The function simply draws a rectangle.
handle must be a valid handle to a printer.
ul_x is the upper left x coordinate of the rectangle.
ul_y is the upper left y coordinate of the rectangle.
lr_x is the lower right x coordinate of the rectangle.
lr_y is the lower right y coordinate of the rectangle.
printer_draw_rectangle example
printer_draw_elipse
Draw an ellipse
Description
voidprinter_draw_elipse
resourcehandle
intul_x
intul_y
intlr_x
intlr_y
The function simply draws an ellipse.
handle must be a valid handle to a printer.
ul_x is the upper left x coordinate of the ellipse.
ul_y is the upper left y coordinate of the ellipse.
lr_x is the lower right x coordinate of the ellipse.
lr_y is the lower right y coordinate of the ellipse.
printer_draw_elipse example
printer_draw_text
Draw text
Description
voidprinter_draw_text
resourceprinter_handle
stringtext
intx
inty
The function simply draws text at position
x, y using the selected
font. printer_handle must be a valid handle to
a printer.
printer_draw_text example
printer_draw_line
Draw a line
Description
voidprinter_draw_line
resourceprinter_handle
intfrom_x
intfrom_y
intto_x
intto_y
The function simply draws a line from position
from_x, from_y to
position to_x, to_y
using the selected pen. printer_handle must
be a valid handle to a printer.
printer_draw_line example
printer_draw_chord
Draw a chord
Description
voidprinter_draw_chord
resourcehandle
intrec_x
intrec_y
intrec_x1
intrec_y1
intrad_x
intrad_y
intrad_x1
intrad_y1
The function simply draws an chord.
handle must be a valid handle to a printer.
rec_x is the upper left x coordinate of the
bounding rectangle.
rec_y is the upper left y coordinate of the
bounding rectangle.
rec_x1 is the lower right x coordinate of the
bounding rectangle.
rec_y1 is the lower right y coordinate of
the bounding rectangle.
rad_x is x coordinate of the radial defining
the beginning of the chord.
rad_y is y coordinate of the radial defining
the beginning of the chord.
rad_x1 is x coordinate of the radial defining
the end of the chord.
rad_y1 is y coordinate of the radial defining
the end of the chord.
printer_draw_chord example
printer_draw_pie
Draw a pie
Description
voidprinter_draw_pie
resourcehandle
intrec_x
intrec_y
intrec_x1
intrec_y1
intrad1_x
intrad1_y
intrad2_x
intrad2_y
The function simply draws an pie.
handle must be a valid handle to a printer.
rec_x is the upper left x coordinate of
the bounding rectangle.
rec_y is the upper left y coordinate of
the bounding rectangle.
rec_x1 is the lower right x coordinate of
the bounding rectangle.
rec_y1 is the lower right y coordinate of
the bounding rectangle.
rad1_x is x coordinate of the first
radial's ending.
rad1_y is y coordinate of the first
radial's ending.
rad2_x is x coordinate of the second
radial's ending.
rad2_y is y coordinate of the second
radial's ending.
printer_draw_chord example
printer_draw_bmp
Draw a bmp
Description
voidprinter_draw_bmp
resourcehandle
stringfilename
intx
inty
The function simply draws an bmp the bitmap
filename at position x,
y. handle must be a
valid handle to a printer.
The function returns &true; on success, or otherwise &false;.
printer_draw_bmp example