> For the complete documentation index, see [llms.txt](https://docs.servoy.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.servoy.com/guides/develop/native-desktop-development/ngdesktop-utils.md).

# NGDesktop Utils

## NGDesktop Utils

Welcome to the **ngdesktoputils** wiki! This wiki provides comprehensive documentation to using the **ngdesktoputils** web service. This service works with the NGDesktop Client as a bridge to execute client side calls from Servoy.

## Getting Started

First import the service using one of the release [binaries](https://github.com/Servoy/ngdesktoputils/releases) or via Servoy's Web Package Manager.

## Example Usage

`//print a pdf document to default system's printer` `plugins.ngdesktoputils.printPDF("/Users/admin/Documents/myZebraFile.pdf");`

```
`//print a pdf document to the specified printer`
`const options = {`
    `printer: "Zebra"`
`}`
`plugins.ngdesktoputils.printPDF("/Users/admin/Documents/myZebraFile.pdf", options);`

`//print a pdf document with options: second page only on windows, and 2 page on one side for Unix like system`
`const options = {`
    `printer: "Zebra",`
    `unix: ["-o number-up=2"], `
    `win32: ['-print-settings "2"']`
`};`

`//For available options on Unix like systems check you system's lp manual (man lp)`
`//For available Windows options check the "Printing options" of the command-line arguments for SumatraPDF: https://www.sumatrapdfreader.org/docs/Command-line-arguments`
```

## API Documentation

### Method Summary

#### exit

This will close the NGDesktop main application. Make sure to application.exit() first to also close the client before closing the desktop application.

#### executeCommand

Executes a command async, the server side call will not block on this call.

**Params**

| Type    | Name   | Summary                                    | Required |
| ------- | ------ | ------------------------------------------ | -------- |
| program | string | Name of program to execute (i.e "cmd.exe") | Required |
| args    | array  | Array of arguments to pass to program      | Optional |

#### executeCommandSync

This executes a command and returns the result of the stdout. This will also call reject when a error happens so the call will error out. (will not return correct). Try to use the async executeCommand if you do not want blocking io.

**Params**

| Type    | Name   | Summary                                    | Required |
| ------- | ------ | ------------------------------------------ | -------- |
| program | string | Name of program to execute (i.e "cmd.exe") | Required |
| args    | array  | Array of arguments to pass to program      | Optional |

#### setClipboardContent

Write the specified text to the system's clipboard.

**Params**

| Type | Name   | Summary                             | Required |
| ---- | ------ | ----------------------------------- | -------- |
| text | string | Text to be written in the clipboard | Required |

#### getClipboardContent

Return the system's clipboard as string.

#### isNGDesktop

Return whether application is running as NGDesktop or not.

#### printPDF

Prints a pdf document specified by path. Optionally, specify printer or unix print options (lp command) or windows print options(SumatraPDF). Options are fully depending on operating system.

For available options on Unix like systems check you system's lp manual (man lp) For available Windows options check the "Printing options" of the command-line arguments for SumatraPDF: <https://www.sumatrapdfreader.org/docs/Command-line-arguments>

**Params**

| Type    | Name   | Summary                                                                   | Required |
| ------- | ------ | ------------------------------------------------------------------------- | -------- |
| path    | string | PDF to be printed                                                         | Required |
| options | string | Printer name or Unix options (lp command) or windows options (SumatraPDF) | Optional |

#### getPrinters

Returns installed printers on local machine.

#### getDefaultPrinter

Returns default printer on local machine.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.servoy.com/guides/develop/native-desktop-development/ngdesktop-utils.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
