Printing Documents

The set of required values for printing a document can be seen in the Print Portal Swagger UI under the AutomatedPrint heading.

To illustrate the API print function, we will use the Swagger UI to post our JSON data that contains the file name, printer, copies, and supporting data needed to print.

ClosedTo print a simple document with no data entry form required

For the first print request, we will use a document that does not have any form data associated with it. The name of the Librarian document is Document1.btw. You can obtain the Library ID by following the tutorial step for Enumerating Libraries. The relative path is the file name. If the file were within a sub-folder, the relative path would include the subfolder name, for example, “Production/Document2.btw”, where Production is the name of the folder. You can simplify the print request, eliminate the root folder element, and then define an absolute path for the file as well (illustrated in the first JavaScript example and below).

{

"AbsolutePath": "c:\\inetpub\\wwwroot\\BarTender\\Templates\\Document1.btw",

"Printer": "PDF",

"Copies": 2,

}

From the above query to get a list of available printers. In this example, we will use the PDF printer for simplicity.

The resulting JSON data describes the file, its parent root folder, the printer, and number of copies.

{

"libraryID": "de6940a6-ff73-465b-aaf2-d39504420fa6",

"relativePath": "Document1.btw",

"printer": "PDF",

"copies": 1

}

Replace “de6940a6-ff73-465b-aaf2-d39504420fa6” with your Librarian ID.

If you want to print directly to your printer, change PDF to one of the valid connected printers.

ClosedTo print a document when a data entry form is required

For a document that has associated form data, for example, TLC39 Laser_53_rf, we will get the document and folder data by using the library ID request return data (see Enumerating Libraries and Enumerating Library Items). We will get the required form data by browsing to the installed Print Portal Templates folder, the Telecommunications sub folder, and its TLC 39 sub folder to print TLC39 Laser_53_rf. Selecting Print will display the form requirements and form default data, as follows:

Files that contain form data require two API passes. You will need to submit the first request in order to get an error message that will list a required "printRequestID.” The initial TLC39 Laser_53_rf and its required form data request will look like the following:

{

"libraryID": "de6940a6-ff73-465b-aaf2-d39504420fa6",

"relativePath": "TLC39 Laser_53_rf.btw",

"printer": "PDF",

"copies": 1,

"DataEntryControls": {

"Text Input Box 1": "GRINGS00102028974810",

"Text Input Box 2": "663726",

"Text Input Box 3": "C5JAB3H1AA",

"Text Input Box 4": "US"

}

}

For the above, replace “de6940a6-ff73-465b-aaf2-d39504420fa6” with your Librarian ID.

The response will be an error containing a required "printRequestID.” Copy the "printRequestID" and add it to you JSON data. The final resulting JSON object including the "printRequestID" will look like the following:

{

"libraryID": "de6940a6-ff73-465b-aaf2-d39504420fa6",

"relativePath": "TLC39 Laser_53_rf.btw",

"printRequestID": "c1cec9ba-1c42-4a74-93e1-96ecf235c403",

"printer": "PDF",

"copies": 1,

"DataEntryControls": {

"Text Input Box 1": "GRINGS00102028974810",

"Text Input Box 2": "663726",

"Text Input Box 3": "C5JAB3H1AA",

"Text Input Box 4": "US"

}

}

Replace “de6940a6-ff73-465b-aaf2-d39504420fa6” with your Librarian ID.

Replace "printRequestID" with your "printRequestID".

Submitting the above will result in a response with the path to the PDF.

ClosedJavaScript Example: Print a simple document with minimal data

Copy
/* ----------------------------------------------------------------------
This example demonstrates how to print a file with no data entry form using as little data as 
possible such as the absolute path where the file is located,
the printer used (in this case is a PDF printer) and the number of copies
*/

// Change this to the URL, library ID, and document path that you want to print
let basePrintPortalURL = "https://example.com/Bartender/";

fetch(basePrintPortalURL + 'print', {
  method: 'post',
  headers: {
    'Content-Type': 'application/json',
    // If authentication is enabled the header requires "'Authorization': 'Bearer ' + token" to be used
  },
  body: JSON.stringify({
            "AbsolutePath": "c:\\inetpub\\wwwroot\\BarTender\\Templates\\Document1.btw",
            "Printer": "PDF",
            "Copies": 2
             })
})
.then(response => response.json())
.then(result => {
  console.log(result);

   // If successful, the pdf file path is displayed
  console.log(result.filePath);

  // The printRequestID is used to continue the print job in case of a fail request
  console.log(result.printRequestID);

  // If not successful, an error message will be displayed stating the reason why. 
  console.log(result.error);

  // Displays the status code of the error message
  console.log(result.statusCode);

})
.catch(error => {
  
    //The error message 'Failed to fetch' will be displayed in case there is an issue with the request
      console.error('There has been a problem with your fetch operation: ', error.message);
}); 

ClosedJavaScript Example: Print a document with a single data entry form

Copy
/*-------------------------------------------------------------------------------------------
Printing a file with a single data entry form and PDF printer */

// Change these to the URL, library ID, and document path that you want to print
let basePrintPortalURL = "https://example.com/Bartender/";
//let token = "token_value_from_authentication_call";

// Process our print job
fetch(basePrintPortalURL + 'print', {
  method: 'post',
  headers: {
    'Content-Type': 'application/json',
    // Make sure we add our authentication header to the print request using the token from previous example
    //'Authorization': 'Bearer ' + token
  },
  body: JSON.stringify({
            "AbsolutePath": "c:\\inetpub\\wwwroot\\BarTender\\wwwroot\\Templates\\Telecommunications/TLC 39/TLC39 Laser_53_rf.btw",
            "Printer": "PDF",
            "Copies": 2,
            "SerialNumbers": 4,
            "DataEntryControls": {
                "Text Input Box 4": "US",
                "Text Input Box 3": "C5JAB3H1AA",
                "Text Input Box 2": "663726",
                "Text Input Box 1": "GRINGS00102028974810"  }
               })
.then(response => response.json())
.then(result => {
  console.log(result);

  // The printRequestID is used to continue the print job in case of a fail request
  console.log(result.printRequestID);

  // Specify the data entry fields required to print the label
  console.log(result.requiredDataEntryControls);

  // If successful, a path of the result pdf lcation should display
  console.log(result.filePath);

  // For physical printers, displays a message "BarTender successfully sent the print job to the spooler."
  console.log(result.messages);

  // If not successful, an error message will be displayed stating the reason why. 
  console.log(result.error);

  // Displays the status code of the error message
  console.log(result.statusCode);

})
.catch(error => {
  console.error('There has been a problem with your fetch operation: ', error.message);
});

ClosedJavaScript Example: Print a document with multiple data entry forms and authentication

Copy
/*----------------------------------------------------------------------
multiple data entry forms and authentication
*/

let basePrintPortalURL = "https://example.com/Bartender/";
let token = "token_value_from_authentication_call";

fetch(basePrintPortalURL + 'print', {
  method: 'post',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + token
  },
  body: JSON.stringify({
        "LibraryID": "9890beae-db51-4b74-a132-d6430a06a192",
        "Relativepath": "Document1.btw",
        "printer": "PDF",
        "copies": 1,
        "DataEntryControls": {
              "Text Input Box 2": "Seattle, WA",
              "Text Input Box 1": "Jon Smith",
              "Date Picker 1": "2020-07-17 00:00:00Z",
              "Text Input Box 3": "Developer",
              "Text Input Box 5": "35 years",
              "Text Input Box 4": "Microsoft"
    }
})

})
.then(response => response.json())
.then(result => {
  console.log(result);
  // The printRequestID is used to continue the print job in case of a fail request
  console.log(result.printRequestID);

  // Specify the data entry fields required to print the label
  console.log(result.requiredDataEntryControls);

  // If successful, a path of the result pdf lcation should display
  console.log(result.filePath);
  
  // For physical printers, displays a message "BarTender successfully sent the print job to the spooler."
  console.log(result.messages);

  //If not successful, an error message will be displayed stating the reason why. 
  console.log(result.error);

  //Displays the status code of the error message
  console.log(result.statusCode);

})
.catch(error => {
  console.error('There has been a problem with your fetch operation: ', error.message);
});

ClosedJavaScript Example: Print a document specifying a relative path and library ID

Copy
/*--------------------------------------------------------------------------------------------
Printing a file specifying the root folder ID and relative path
This document has no data entry form */

let basePrintPortalURL = "https://example.com/Bartender/";
let token = "token_value_from_authentication_call";

fetch(basePrintPortalURL + 'print', {
  method: 'post',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + token
  },
  body: JSON.stringify({
              "LibraryID": "9890beae-db51-4b74-a132-d6430a06a192",
              "Relativepath": "Document1.btw",
              "Printer": "Zebra GX430d - ZPL",
              "Copies": 2,
             })
               })
.then(response => response.json())
.then(result => {
  console.log(result);

  // The printRequestID is used to continue the print job in case of a fail request
  console.log(result.printRequestID);

  // Specify the data entry fields required to print the label
  console.log(result.requiredDataEntryControls);
 
 // For physical printers, displays a message "BarTender successfully sent the print job to the spooler."
  console.log(result.messages);

 // If not successful, an error message will be displayed, ""
  console.log(result.error);

 // Displays the status code of the error message
  console.log(result.statusCode);
})
.catch(error => {
  console.error('There has been a problem with your fetch operation: ', error.message);
});