How to: Use Web API Printing
A few printing methods are available via WebAPI. This is done by sending HTTP requests to Hardware Station.
To test the WebAPI functionality
We recommend using an API testing tool like Postman when testing and setting up WebAPI requests.
Print Raw
The PrintRaw function can print PDF documents, labels, and more to a Windows printer (not OPOS). LS Central currently uses this function to print PDF receipts and shelf labels. The PrintRaw function takes a byte array stream as parameter, which can be seen in the LS Central implementation.
The URL for the request is structured like this:
-
{http(s)}://{hotstname}:{port}/api/printer/{printerID}/printraw
It also has two aliases so either of these URLs can be used as well to the same effect:
- {http(s)}://{hotstname}:{port}/api/printer/{printerID}/printpdf
- {http(s)}://{hotstname}:{port}/api/printer/{printerID}/printlabel
Note: Replace the values in the curly brackets with your own parameters
Direct PDF printing is not supported by all printer types. In those instances Hardware Station will not be able to print PDF documents. A workaround for this is to select the Save to File option in the Management Portal which bypasses the printer and writes the PDF stream to file at C:\ProgramData\LS Retail\LS Hardware Station\pdf. From there it can be manually printed, or a script can be written to watch the folder and print the documents when they appear there.
Query String printing
Printing a stream can also be done using a query string format. This means that instead of:
- {http(s)}://{hotstname}:{port}/api/printer/{printerID}/printraw
the same method can be called like this:
- {http(s)}://{hotstname}:{port}/api/printer/printraw?printer={printerID}
The other aliases also work. The reason this may be preferable is that it accepts more diverse strings, such as ones with backslashes. For example, if the printer name is a network printer with a name like \\123.123.123.123\NETWORK_PRINTER, it would only work as a query string but not the method mentioned above.
Print Buffer
There is also a HTTP version of the PrintBuffer function. It is similar to its SignalR counterpart.
The URL for the request is structered like this:
- {http(s)}://{hotstname}:{port}/api/printer/{printerID}/printbuffer
PrintBuffer takes a JSON array in the body of the request in the same form as the SignalR version does as parameters. The array is a collection of objects formatted like this:
{
timestamp: string,
Store No.: string,
Terminal No.: string,
Transaction No.: int,
Entry No.: int,
Buffer Index: int,
Station No.: int,
Page No.: int,
Printed Line No.: int,
LineType: int,
FiscalLineType: int,
HostID: string,
ProfileID: string,
TransactionType: int,
Text: string,
Width: int,
Height: int,
BCType: string,
BCPos: int,
SetBackPrinting: bool,
FontType: int,
Training: bool,
Xml: string,
DesignText: string
}
To test the WebAPI functionality
To test this functionality, use the PrintTest function. This function simply prints out a test receipt, same as the Print Test Receipt button in the Management Portal. This test function is very useful for testing the connection to the Hardware Station and if the HTTP request is valid.
The URL for the request is structured like this:
- {http(s)}://{hotstname}:{port}/api/printer/{printerID}/printtest
Note: Replace the values in the curly brackets with your own parameters.
An example of a print test on the virtual printer:
- localhost:8082/api/printer/VIRTUAL_P1/printtest
A print test takes no payload as the test receipt is created in the test function itself.