Cloud Print API

Cloud_Bus_Ent.png

Cloud Print API (or Cloud Printing) lets you print from any application or device to any connected printer, regardless of printer location. This includes your connected cloud printers and all printers connected to any active workstation with Loftware solutions installed.

Note: Cloud-connected printers are smart printers that don't require a local installation of printer drivers. With cloud printers, you print via the cloud. You don't need a local connection.

Printing to local printers requires printer drivers. We recommend you use Loftware printer drivers.

Note: You can use custom fonts with your cloud printers. Custom fonts are fonts that are not provided with standard Windows installation. See the dedicated topic with detailed instructions on uploading and using custom fonts.

With Cloud Print API, you can:

  • Send print stream data directly to your Cloud Print connected printers.
  • Print labels you save in document storage in Control Center.

Cloud Print API works with:

  • Loftware products using HTTP Request actions (automatic API authentication).

Note: With (Undefined variable: LoftwareCloudVariables.LoftwareAutomation) there is no need for custom header.

  • Other products using Cloud Print API (manual API authentication):

    • SAP
    • Mobile apps
    • Web apps
    • And more

You can test the Cloud Print API on the Developer Portal.

The Developer Portal is where you can test Loftware​​ APIs and see how they interact with your label printing system.

Note: Developer Portal includes auto-generated code samples in multiple programming languages.

To use Cloud Print API on the Developer Portal, you must:

  • Set up your Developer Portal account.

  • Create your free subscription for our Loftware Cloud product.

  • Connect your Developer Portal subscription with Control Center.

To set up your Developer Portal account, create subscriptions, and connect your Developer Portal to Loftware Control Center​​, follow the steps in ​Cloud integrations​​.

Using Cloud Print API

After you subscribe to Loftware Cloud API on the Developer Portal and connect your subscription, you can test how Cloud Print API works. There are two calls in Cloud Print APIs:

  • ​​GET​​ requests data from a specified resource.

  • ​​POST​​ sends data to a server to create/update a resource.

​There are three operations in Cloud Print API:

  • ​POST Print​​ prints labels to your connected printer.

  • GET Printers​​ gets a list of all your connected printers.

  • POST SendData​​ sends your generated streams to your printers.

Printing or recalling labels saved in Document Storage with Cloud Print API

Test how printing works for labels stored in Document Storage in Control Center using API:

  1. Sign in to the Developer Portal.

  2. Go to APIs > Cloud Print API and click Cloud Print API - v2. The Cloud Print API page opens.

  3. Click Try it.

  4. Select your content type (JSON or XML, your Request body changes).

In your Request body:

Note: Only use JSON format for the Request Body.

  1. Type your printer ​deviceType​ and ​deviceId​ (including ​printerName​ and ​workstation​​).

    Note: To get your deviceType and deviceId, go to ​Cloud Print API​ page > ​GET Printers API​ > ​Try it​​. Select or confirm your subscription key and click ​Send​​. In ​Response content​​, you see all your connected printers in JSON format. Find your selected printer and copy the data.

    ​​CloudPrinter​​ refers to printers with built-in cloud printing capabilities. Cloud printers must be connected to Loftware Cloud.
    ​​PrintQueue​​ refers to other (non-cloud) printers.

  2. Type the file path for your label in Document Storage in Control Center. You can use label files (.nlbl) or solutions (.nsln). For solutions, define your label name:

    Label:

    Copy
    "FilePath": "/MyFolder/MyLabel.nlbl",

    Solution:

    Copy
    "FilePath": "/Labels/YourSolution.nsln",

    Label name:

    Copy
    "LabelName": "YourLabel1",
  3. Optional: Set the ​printerSettings​​. To use specific printer settings, Base64 encode your devmode.

    Note: You can use DEVMODE to send printer settings directly to your printer with your print request. Read more about ​DEVMODE​​.

  4. Type the quantity of labels to print. To print 3 labels, type:

    Copy
    "Quantity": 3,
  5. Set the ​dataSources​​, where appropriate. For simple labels or test prints, delete this section.

    Note: You can use multiple arrays for each label. The example below shows one array in "dataSources". The print out will be one label with values, set in the array.

    Copy
    {
      "deviceType": "CloudPrinter",
      "deviceId": {
        "printerName": "Warehouse1",
        "workstation": null
      },
      "filePath": "/Labels/ShippingLabels/helloworld.nlbl",
      "quantity": "1",
      "dataSources": [
        {
          "WHS_LABEL_ID": "012345",
          "LICENSEPLATE_ID": "012345",
          "LABEL_NAME": "helloworld",
          "BATCH_ID": "BAT12345",
          "PROD_DATE": "2024-07-17",
          "EXP_DATE": "2025-07-17",
          "NET_WEIGHT": "1,00x500,00",
          "PRODUCT_NAME": "FreshPasta500",
          "ITEM_ID": "LOT12345"
        }
      ]
    }
  6. Optional: Define your file version in the FileRevision field.

    Note: If you skip the FileRevision field, the last approved version of your label template prints, even if it has not been checked in yet. If you use an empty value for FileRevision, a current "working" copy of the label prints, that has not been checked in yet and has no file version.

  7. Remove the lines for any skipped fields. Here is an example of a populated Request body with the minimum required fields (Revision, Print Settings, and Data Sources were not used):


  8. Click Send.

Your printer prints your label.

Listing cloud printers with Cloud Print API

When you develop applications where users print labels with cloud printers, use API to get a list of your registered cloud printers (you can see cloud printers in Control Center under Printers > Cloud Printers):

  1. Sign in to the Developer Portal.

  2. Go to APIs > Cloud Print API and click v2. The Cloud Print API page opens.

  3. Go to Printers and click Try it.

  4. Click Send.

In Response content, the Developer Portal displays your printers, installed on all workstations with Loftware Cloud.

Sending data to your printers with Cloud Print API

If you use applications that generate print streams, store streams, or recall streams, use the SendData action to send your generated streams to your printers. The SendData action sends generated streams or raw commands in printer-specific language. Base64 encoding ensures your labels print special characters correctly.

Note: If you print to local printers, printing requires printer drivers. If you print to cloud-connected printers, printer drivers are not required.

  1. Sign in to the Developer Portal.

  2. Go to APIs > Cloud Print API and click v2. The Cloud Print API page opens.

  3. Go to SendData and click Try it.

In your Request body, type your printer name (for cloud printers registered in Loftware Control Center), then send Base64 encoded data to your printer:

  1. Generate your stream (in Loftware Desktop Designer, print your label to file, or use your own external applications to generate .prn files.).

  2. Convert your stream to Base64 (for testing, you can use online conversion tools).

  3. Paste or type your Base64-encoded stream into your request body.

  4. Click Send.

If you encoded a label print stream, your printer prints your label.