import { Callout } from "zudoku/ui/Callout";

# 365 business Print Agent

`365 business Print Agent` connects the printers of your infrastructure to Microsoft Dynamics 365 Business Central. A Print Agent Client runs next to the printers, Business Central hands it print jobs, and the client prints them - which is how a cloud tenant reaches a label printer in a warehouse.

This page is the entry point for using the app from your own extension. There are two ways to do that:

| You want to | Start here |
| --- | --- |
| Send something to a printer from your own code - a PDF, ZPL commands, raw data | [Print Agent](print-agent.mdx) |
| React to a printer or a client that stops working | [Extensibility Events](extensibility-events.mdx) |

## Dependency

Add a dependency to the `365 business Print Agent` app in the `dependencies` node of your `app.json`:

```json
    {
      "id": "6fb30c19-f5d6-4e4c-b006-18fba4de1898",
      "name": "365 business Print Agent",
      "publisher": "365 business development",
      "version": "18.12.0.0"
    }
```

## The public objects

The objects below are the supported surface of the app. Everything else is `Access = Internal` or an implementation detail that may change without notice, even where AL leaves it public.

| Object | Type | What it is for |
| --- | --- | --- |
| `bdev.Print Agent` | Codeunit (`5523742`) | [Send print jobs](print-agent.mdx): PDF documents, ZPL commands and raw data. |
| `bdev.Print Agent Events` | Codeunit (`5523820`) | The [monitoring events](extensibility-events.mdx): a client or a printer that went offline or into failure. |
| `bdev.PrA Printer Configuration` | Table (`5523743`) | A named way of printing at a printer - duplex, color, tray, number of copies, page ranges. What every print method addresses. Publishes [one event](extensibility-events.mdx#ontryenableprinterconfigurationfailed---event). |
| `bdev.PrA Printer Conf. Lines` | Table (`5523744`) | The page ranges of a printer configuration, each with its own paper source. |
| `bdev.Print Agent Printers` | Table (`5523739`) | The printers the clients report, with their capabilities and their current status. |
| `bdev.PrA Printer Access Perm.` | Table (`5523740`) | Which users may print at which printer. |

## Everything goes through a printer configuration

A print method never addresses a printer directly - it addresses a **printer configuration**. The configuration names the printer and states how to print: duplex, color, number of copies, which tray, which page range goes where. That is what makes it possible to change the printing of a process without touching the code that prints.

<Callout type="caution" title="The parameter called printerName is the configuration code">
Every method comes in two flavors: one taking a `bdev.PrA Printer Configuration` record, one taking a `printerName: Text[250]`. Despite the name, that text is looked up as the **`Code` of the printer configuration**, not as the name of a printer. Passing an actual printer name works only where a configuration happens to carry the same code.
</Callout>

The overloads taking a name raise an error when no configuration with that code exists or when the configuration is disabled. The overloads taking a record do not check: pass a configuration you read yourself, and test `Enabled` before you print.

## How a failure reports itself

A print method never returns a value. Whether the job reached the client is answered afterwards by [IsPrinted](print-agent.mdx#isprinted), and the reason by `GetLastErrorText()`. Errors that happen before the job is built - an unknown configuration, a client too old for raw printing - are raised as ordinary AL errors instead.

## Requirements beyond Business Central

A print job needs more than the app: a Print Agent Client has to be installed, registered and online, the printer has to be known to that client, and the printer configuration has to be enabled. None of that is in your hands as an extension developer, but all of it decides whether your print works - which is why the [monitoring events](extensibility-events.mdx) exist.

## See also

- [Print Agent](print-agent.mdx)
- [Extensibility Events](extensibility-events.mdx)
- [Documentation - Printer Configuration](../../en-us/365-business-print-agent/printer-configuration.mdx)
- [Documentation - 365 business Print Agent](../../en-us/365-business-print-agent/index.mdx)
