<div class="meta" robots="noindex">

</div>

Method

# OpenPrinter

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2019r2. Please use `PrinterSetup.OpenPrinter<printersetup.openprinter>` as a replacement.

</div>

## Description

Returns a `Graphics</api/graphics/graphics>` object in order to print to the currently selected printer.

## Usage

*result* = **OpenPrinter**(\[*ps As PageSetup*\])

| Part      | Type                                       | Description                                                                                                                                                                                                                                                                             |
|-----------|--------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| result    | `Graphics</api/graphics/graphics>`         | A `graphics</api/graphics/graphics>` object that represents the page to be printed.                                                                                                                                                                                                     |
| PageSetup | `PrinterSetup</api/printing/printersetup>` | Optional. A `PrinterSetup</api/printing/printersetup>` object whose properties will be used (like page orientation, scale, etc.) when printing. Although this is optional, you will mostly likely always want to provide a PrinterSetup so that you have access to drawing resolutions. |

## Notes

The <span class="title-ref">OpenPrinter</span> function returns a `Graphics</api/graphics/graphics>` object. The various drawing routines can then be used to draw into the `Graphics</api/graphics/graphics>` object and will be sent to the printer for printing.

Although the pageSetup parameter is optional, in order to get the correct horizontal and vertical resolutions for drawing and positioning you will need to provide a PrinterSetup. You can do this without prompting the user with a dialog like this:

``` xojo
Dim p As New PageSetup
g = OpenPrinter(p)
Dim horizontalDPI = p.HorizontalResolution
Dim verticalDPI = p.VerticalResolution
```

## Sample code

This code prints "Hello World" to the currently selected printer:

``` xojo
Dim p As New PageSetup
Dim g As Graphics
g = OpenPrinter(p)
If g <> Nil Then
  ' Draw text 1 inch across and 1 inch down
  g.DrawString("Hello World", p.HorizontalResolution, p.VerticalResolution)
End If
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This code uses the Page Setup properties for the printer chosen by the user by the PageSetup dialog:

``` xojo
Dim ps As New PrinterSetup
If ps.PageSetupDialog Then
  Dim g As Graphics
  g = OpenPrinter(ps)
  If g <> Nil Then
    ' Draw text 1 inch across and 1 inch down
    g.DrawString("Hello World", ps.HorizontalResolution, ps.VerticalResolution)
  End If
End If
```

## Compatibility

All project types on all supported operating systems.

## See also

`Graphics</api/graphics/graphics>`, `PrinterSetup</api/printing/printersetup>` classes; `ShowPrinterDialog<printersetup.showprinterdialog>` function.
