Table of Contents

365 Business Print Agent

The 365 Business Print Agent app adds printing capabilities and integrates your printer infrastructure with Microsoft Dynamics 365 Business Central.


App Dependencies

To create your own implementation, add a dependency to the 365 Business Print Agent app by including the following in the dependencies node of your app.json file:

{
  "id": "6fb30c19-f5d6-4e4c-b006-18fba4de1898",
  "name": "365 Business Print Agent",
  "publisher": "365 Business Development",
  "version": "18.0.0.0"
}

Implementation

The 365 Business Print Agent app provides an internal API codeunit to allow integration with custom-specific business processes. For example, you can print external PDF documents to a specified Printer Configuration.


Methods

Overview

The bdev.Print Agent codeunit object provides the following public methods:

Method Description
IsPrinted(): Boolean Returns the status of the last print job execution.
PrintPdf(Text, Codeunit, Record) Prints a PDF document in Temp Blob at the specified Printer Configuration.
PrintPdf(Text, Codeunit, Integer, Record) Prints the specified number of copies of the PDF document in Temp Blob at the specified Printer Configuration.
PrintPdf(Codeunit, Record) Prints a PDF document in Temp Blob at the specified Printer Configuration.
PrintPdf(Codeunit, Integer, Record) Prints the specified number of copies of the PDF document in Temp Blob at the specified Printer Configuration.
PrintPdf(Text, InStream, Record) Prints a PDF document stream at the specified Printer Configuration.
PrintPdf(Text, InStream, Integer, Record) Prints the specified number of copies of the PDF document stream at the specified Printer Configuration.
PrintPdf(InStream, Record) Prints a PDF document stream at the specified Printer Configuration.
PrintPdf(InStream, Integer, Record) Prints the specified number of copies of the PDF document stream at the specified Printer Configuration.
PrintZPL(Text, Text, Record) Sends Zebra Programming Language (ZPL) commands to the specified Printer Configuration.
PrintZPL(Text, Record) Sends Zebra Programming Language (ZPL) commands to the specified Printer Configuration.
PrintRAW(Text, InStream, Record) Prints RAW data stream at the specified Printer Configuration.
PrintRAW(InStream, Record) Prints RAW data stream at the specified Printer Configuration.
PrintRAW(Text, Record) Prints RAW data at the specified Printer Configuration.

Method Details

IsPrinted() procedure

Description: Returns the status of the last print job execution.

Remarks: Use GetLastErrorText() to get further information if a print job has not been executed successfully.

Return:

  • True if the previous print job has been executed successfully.
  • False otherwise.

Example:

procedure MyCustomPrint(documentName: Text; var tempBlob: Codeunit "Temp Blob"; printerConfigurationCode: Text[250])
var
    printerConfiguration: Record "bdev.PrA Printer Configuration";
    printAgent: Codeunit "bdev.Print Agent";
    printJobFailedErr: Label 'The print job failed with the following error message: %1', Comment = '%1 = Error message';
begin
    if (not printerConfiguration.Get(printerConfigurationCode)) then
        exit;

    if (not printerConfiguration.Enabled) then
        exit;

    printAgent.PrintPdf(
        documentName,
        tempBlob,
        printerConfiguration
    );

    if (not printAgent.IsPrinted()) then
        Error(
            printJobFailedErr,
            GetLastErrorText()
        );
end;

PrintPdf(Text, Codeunit, Record) procedure

Description: Prints a PDF document in Temp Blob at the specified bdev.PrA Printer Configuration.

Remarks: The documentName parameter is used only for the history view in the 365 Business Print Agent application.

Example:

printAgent.PrintPdf(documentName, tempBlob, printerConfiguration);

PrintPdf(Text, Codeunit, Integer, Record) procedure

Description: Prints the specified number of copies of the PDF document in Temp Blob at the specified bdev.PrA Printer Configuration.

Remarks:

  • The documentName parameter is used only for the history view in the 365 Business Print Agent application.
  • The noOfCopies parameter specifies the number of additional copies to be printed. For example, if you want to print just the original document, specify noOfCopies = 0. To print the original document and one copy, specify noOfCopies = 1.

PrintPdf(Codeunit, Record) procedure

Description: Prints a PDF document in Temp Blob at the specified bdev.PrA Printer Configuration.

Remarks: If the documentName parameter is omitted, External PDF Document will be used as the document name. The name of the document is displayed in the history view of the 365 Business Print Agent application.

PrintPdf(Codeunit, Integer, Record) procedure

Description: Prints the specified number of copies of the PDF document in Temp Blob at the specified bdev.PrA Printer Configuration.

Remarks:

  • If the documentName parameter is omitted, External PDF Document will be used as the document name. The name of the document is displayed in the history view of the 365 Business Print Agent application.
  • The noOfCopies parameter specifies the number of additional copies to be printed. For example, if you want to print just the original document, specify noOfCopies = 0. To print the original document and one copy, specify noOfCopies = 1.

PrintPdf(Text, InStream, Record) procedure

Description: Prints a PDF document stream at the specified bdev.PrA Printer Configuration.

Remarks: The documentName parameter is used only for the history view in the 365 Business Print Agent application.

Example:

printAgent.PrintPdf(documentName, streamIn, printerConfiguration);

PrintPdf(Text, InStream, Integer, Record) procedure

Description: Prints the specified number of copies of the PDF document stream at the specified bdev.PrA Printer Configuration.

Remarks:

  • The documentName parameter is used only for the history view in the 365 Business Print Agent application.
  • The noOfCopies parameter specifies the number of additional copies to be printed. For example, if you want to print just the original document, specify noOfCopies = 0. To print the original document and one copy, specify noOfCopies = 1.

Example:

printAgent.PrintPdf(documentName, streamIn, noOfCopies, printerConfiguration);

PrintPdf(InStream, Record) procedure

Description: Prints a PDF document stream at the specified bdev.PrA Printer Configuration.

Remarks: If the documentName parameter is omitted, External PDF Document will be used as the document name. The name of the document is displayed in the history view of the 365 Business Print Agent application.

Example:

printAgent.PrintPdf(streamIn, printerConfiguration);

PrintPdf(InStream, Integer, Record) procedure

Description: Prints the specified number of copies of the PDF document stream at the specified bdev.PrA Printer Configuration.

Remarks:

  • If the documentName parameter is omitted, External PDF Document will be used as the document name. The name of the document is displayed in the history view of the 365 Business Print Agent application.
  • The noOfCopies parameter specifies the number of additional copies to be printed. For example, if you want to print just the original document, specify noOfCopies = 0. To print the original document and one copy, specify noOfCopies = 1.

Example:

printAgent.PrintPdf(streamIn, noOfCopies, printerConfiguration);

PrintZPL(Text, Text, Record) procedure

Description: Sends ZPL commands to the specified bdev.PrA Printer Configuration.

Important
Sending ZPL commands is only supported for Zebra printers. Sending ZPL commands to other printers may cause unforeseen errors.

Remarks: The documentName parameter is used only for the history view in the 365 Business Print Agent application.

Additional Resources:

Zebra Programming Language (ZPL) is the command language used by all ZPL-compatible printers. It is a command-based language used by the printers as instructions to create the images printed on the labels. You can find ZPL Command Information and Details at the following link:

Example:

printAgent.PrintZPL(documentName, zplCommands, printerConfiguration);

PrintZPL(Text, Record) procedure

Description: Sends ZPL commands to the specified bdev.PrA Printer Configuration.

Important
Sending ZPL commands is only supported for Zebra printers. Sending ZPL commands to other printers may cause unforeseen errors.

Remarks:

  • If the documentName parameter is omitted, ZPL commands will be used as the document name. The name of the document is displayed in the history view of the 365 Business Print Agent application.
  • The zplCommands parameter contains the ZPL commands to be sent to the printer.

Additional Resources:

Zebra Programming Language (ZPL) is the command language used by all ZPL-compatible printers. It is a command-based language used by the printers as instructions to create the images printed on the labels. You can find ZPL Command Information and Details at the following link:

Example:

printAgent.PrintZPL(zplCommands, printerConfiguration);

PrintRAW(Text, InStream, Record) procedure

Description: Prints RAW data stream at the specified bdev.PrA Printer Configuration.

Info Available starting version 18.12.230.20314.

Remarks: The documentName parameter is used only for the history view in the 365 Business Print Agent application.

Example:

printAgent.PrintRAW(documentName, stream, printerConfiguration);

PrintRAW(InStream, Record) procedure

Description: Prints RAW data stream at the specified bdev.PrA Printer Configuration.

Info Available starting version 18.12.230.20314.

Remarks: If the documentName parameter is omitted, External RAW Data will be used as the document name. The name of the document is displayed in the history view of the 365 Business Print Agent application.

Example:

printAgent.PrintRAW(stream, printerConfiguration);

PrintRAW(Text, Record) procedure

Description: Prints RAW data at the specified bdev.PrA Printer Configuration.

Info Available starting version 18.12.230.20314.

Remarks: If the documentName parameter is omitted, External RAW Data will be used as the document name. The name of the document is displayed in the history view of the 365 Business Print Agent application.

Example:

printAgent.PrintRAW(rawData, printerConfiguration);

Events

Overview

The 365 Business Print Agent app provides a codeunit to subscribe to various events.

Event Publisher Description
PrintAgentClientOfflineEvent(Text, DateTime) Event raised when a Print Agent Client goes offline.
PrinterOfflineEvent(Text, Text, Text) Event raised when a printer goes offline.
PrinterFailureEvent(Text, Text, Text) Event raised when a printer goes into failure mode.

Event Details

PrintAgentClientOfflineEvent(Text, DateTime)

Description: Event raised when a Print Agent Client goes offline.

Parameters:

Parameter Description
printAgentName Name of the print agent client service.
lastSeen Date/time the print agent client service was last seen.

PrinterOfflineEvent(Text, Text, Text)

Description: Event raised when a printer goes offline.

Parameters:

Parameter Description
printAgentName Name of the print agent client service hosting the printer.
printerName Name of the printer.
status Current status of the printer, e.g., 'Not available' or 'Offline'.

PrinterFailureEvent(Text, Text, Text)

Description: Event raised when a printer goes into failure mode.

Parameters:

Parameter Description
printAgentName Name of the print agent client service hosting the printer.
printerName Name of the printer.
status Current status of the printer, e.g., 'Low Toner'.