# Printers

## Methods

### <mark style="color:purple;">Print</mark>

Attempts to print the web page.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.printers.print({ arguments })
```

**Arguments**

* `windowId` <mark style="color:green;">String</mark> (Optional)\
  The ID of the window to print. Defaults to the current window.
* `silent` <mark style="color:green;">Boolean</mark> (Optional)\
  Don't ask user for print settings. Default is `false`.
* `printBackground` <mark style="color:green;">Boolean</mark> (Optional)

  Prints the background color and image of the web page. Default is `false`.
* `deviceName` <mark style="color:green;">String</mark> (Optional)\
  Set the printer device name to use. Must be the system-defined name and not the 'friendly' name, e.g 'Brother\_QL\_820NWB' and not 'Brother QL-820NWB'.
* `color` <mark style="color:green;">Boolean</mark> (Optional)

  Set whether the printed web page will be in color or grayscale. Default is `true`.
* `margins` <mark style="color:green;">Object</mark> (Optional)
  * `marginType` <mark style="color:green;">String</mark>

    Can be `default`, `none`, `printableArea`, or `custom`. If `custom` is chosen, you will also need to specify `top`, `bottom`, `left`, and `right`.
  * `top` <mark style="color:green;">Number</mark>\
    The top margin of the printed web page, in pixels.
  * `bottom` <mark style="color:green;">Number</mark>\
    The bottom margin of the printed web page, in pixels.
  * `left` <mark style="color:green;">Number</mark>\
    The left margin of the printed web page, in pixels.
  * `right` <mark style="color:green;">Number</mark>\
    The right margin of the printed web page, in pixels.
* `landscape` <mark style="color:green;">Boolean</mark> (Optional)\
  Whether the web page should be printed in landscape mode. Default is `false`.
* `scaleFactor` <mark style="color:green;">Number</mark> (Optional)\
  The scale factor of the web page.
* `pagesPerSheet` <mark style="color:green;">Number</mark> (Optional)\
  The number of pages to print per page sheet.
* `collate` <mark style="color:green;">Boolean</mark> (Optional)\
  Whether the web page should be collated.
* `copies` <mark style="color:green;">Number</mark> (Optional)\
  The number of copies of the web page to print.
* `pageRanges` Array of <mark style="color:green;">Objects</mark> (Optional)\
  The page range to print. On macOS, only one range is honored.
  * `from` <mark style="color:green;">Number</mark>\
    Index of the first page to print (0-based).
  * `to` <mark style="color:green;">Number</mark>\
    Index of the last page to print (inclusive) (0-based).
* `duplexMode` <mark style="color:green;">String</mark> (Optional)\
  Set the duplex mode of the printed web page. Can be `simplex`, `shortEdge`, or `longEdge`.
* `dpi` <mark style="color:green;">Object</mark> (Optional)
  * `horizontal` <mark style="color:green;">Number</mark>\
    The horizontal dpi.
  * `vertical` <mark style="color:green;">Number</mark>\
    The vertical dpi.
* `header` <mark style="color:green;">String</mark> (Optional)\
  string to be printed as page header.
* `footer` <mark style="color:green;">String</mark> (Optional)\
  string to be printed as page footer.
* `pageSize` <mark style="color:green;">String</mark> (Optional)\
  Specify page size of the printed document. Can be `A0`, `A1`, `A2`, `A3`, `A4`, `A5`, `A6`, `Legal`, `Letter`, `Tabloid` or an Object containing `height` and `width`.

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful. If the user cancels the print, this will return false.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful.

**Example**

{% code overflow="wrap" %}

```javascript
const result = await window.deskifier.printers.print({ windowId: 'main' });

console.log(result.success);  // true
```

{% endcode %}
{% endtab %}
{% endtabs %}

***

### <mark style="color:purple;">Print To PDF</mark>

Attempts to create a PDF from the web page.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.printers.printToPdf({ arguments })
```

**Arguments**

* `windowId` <mark style="color:green;">String</mark>

  The ID of the window to print. Defaults to the current window.
* `filePath` <mark style="color:green;">String</mark> (Required)\
  The path to save the PDF file to.
* `landscape` <mark style="color:green;">Boolean</mark> (Optional)\
  Paper orientation. `true` for landscape, `false` for portrait. Defaults to false.
* `displayHeaderFooter` <mark style="color:green;">Boolean</mark> (Optional)\
  Whether to display header and footer. Defaults to false.
* `printBackground` <mark style="color:green;">Boolean</mark> (Optional)\
  Whether to print background graphics. Defaults to false.
* `scale` <mark style="color:green;">Number</mark> (Optional)\
  Scale of the webpage rendering. Defaults to 1.
* `pageSize` <mark style="color:green;">String</mark> (Optional)\
  Specify page size of the generated PDF. Can be `A0`, `A1`, `A2`, `A3`, `A4`, `A5`, `A6`, `Legal`, `Letter`, `Tabloid`, `Ledger`, or an Object containing `height` and `width` in inches. Defaults to `Letter`.
* `margins` <mark style="color:green;">Object</mark> (Optional)
  * `top` <mark style="color:green;">Number</mark>\
    Top margin in inches. Defaults to 1cm (\~0.4 inches).
  * `bottom` <mark style="color:green;">Number</mark>\
    Bottom margin in inches. Defaults to 1cm (\~0.4 inches).
  * `left` <mark style="color:green;">Number</mark>\
    Left margin in inches. Defaults to 1cm (\~0.4 inches).
  * `right` <mark style="color:green;">Number</mark>\
    Right margin in inches. Defaults to 1cm (\~0.4 inches).
* `pageRanges` <mark style="color:green;">String</mark> (Optional)\
  Page ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
* `headerTemplate` <mark style="color:green;">String</mark> (Optional)\
  HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them: `date` (formatted print date), `title` (document title), `url` (document location), `pageNumber` (current page number) and `totalPages` (total pages in the document). For example, `<span class=title></span>` would generate span containing the title.
* `footerTemplate` <mark style="color:green;">String</mark> (Optional)\
  HTML template for the print footer. Should use the same format as the `headerTemplate`.
* `preferCSSPageSize` <mark style="color:green;">Boolean</mark> (Optional)\
  Whether or not to prefer page size as defined by css. Defaults to false, in which case the content will be scaled to fit the paper size.

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful.
* `path` <mark style="color:green;">String</mark>\
  The file path of the saved PDF.
  {% endtab %}
  {% endtabs %}

***

## Properties

### <mark style="color:purple;">Get Printers</mark>

Returns all printers connected to the device.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.printers.getAll()
```

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful.
* `printers` Array of [si.Printer](https://systeminformation.io/printer.html)
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://deskifier.gitbook.io/deskifier/printers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
