Skip to main content
Send a print job to a configured thermal printer.

Message Format

{
  "JobId": "job_12345",
  "StationId": "STATION_001",
  "PrinterId": "PRINTER_001",
  "DocumentType": "ticket_venta",
  "Document": {
    "Number": "FAC-001234",
    "Date": "2024-01-15",
    "CustomerName": "John Doe",
    "Items": [
      {
        "Name": "Product A",
        "Quantity": 2,
        "Price": 10.50,
        "Total": 21.00
      }
    ],
    "Subtotal": 21.00,
    "Tax": 1.68,
    "Total": 22.68
  },
  "Images": [
    {
      "Id": "logo",
      "Base64": "iVBORw0KGgoAAAANSUhEUgAAAAUA...",
      "Align": "center",
      "WidthMm": 40
    }
  ],
  "Barcodes": [
    {
      "Type": "CODE128",
      "Value": "FAC-001234",
      "Height": 50,
      "Width": 2,
      "Hri": true,
      "ItemId": "item_001",
      "Name": "Product A",
      "Price": "$10.50"
    }
  ],
  "QRs": [
    {
      "Value": "https://example.com/invoice/001234",
      "Size": 6,
      "Align": "center"
    }
  ]
}

Request Fields

JobId
string
required
Unique identifier for this print job. Used to match results with requests.
StationId
string
required
Identifier of the station or point-of-sale terminal originating the request.
PrinterId
string
required
Identifier of the target printer. Must match a printer ID in APM configuration.
DocumentType
string
required
Type of document to print. Determines which template is used. Common values:
  • ticket_venta - Sales receipt
  • comanda - Kitchen order
  • factura_electronica - Electronic invoice
  • sticker - Product label/sticker
Document
object
required
The main document data. Structure varies by document type and template configuration. Contains the business data to be printed (invoice details, order items, etc.).
Images
array
List of images to include in the printout (e.g., logos, signatures).
Barcodes
array
List of barcodes to print.
QRs
array
List of QR codes to print.
After processing a print job, APM sends a result message back to the requesting client.

Message Format

Success

{
  "JobId": "job_12345",
  "Status": "DONE",
  "ErrorMessage": null
}

Error

{
  "JobId": "job_12345",
  "Status": "ERROR",
  "ErrorMessage": "Printer PRINTER_001 not found in configuration"
}

Response Fields

JobId
string
The job identifier from the original request.
Status
string
Final status of the print job:
  • DONE - Print job completed successfully
  • ERROR - Print job failed
ErrorMessage
string
Error details if Status is ERROR, otherwise null.

Example: Complete Print Flow

const ws = new WebSocket('ws://localhost:7000/websocket/');

ws.onopen = () => {
  // Send print job
  const printJob = {
    JobId: `job_${Date.now()}`,
    StationId: 'STATION_001',
    PrinterId: 'PRINTER_001',
    DocumentType: 'ticket_venta',
    Document: {
      Number: 'FAC-001234',
      Date: new Date().toISOString(),
      Items: [
        { Name: 'Coffee', Quantity: 1, Price: 3.50, Total: 3.50 }
      ],
      Total: 3.50
    },
    Images: [],
    Barcodes: [],
    QRs: []
  };
  
  ws.send(JSON.stringify(printJob));
};

ws.onmessage = (event) => {
  const result = JSON.parse(event.data);
  
  // Check if this is a print job result
  if (result.JobId && result.Status) {
    if (result.Status === 'DONE') {
      console.log(`Print job ${result.JobId} completed successfully`);
    } else if (result.Status === 'ERROR') {
      console.error(`Print job ${result.JobId} failed: ${result.ErrorMessage}`);
    }
  }
};

Document Types

The DocumentType field determines which print template is used. Common types:
Document TypeDescriptionTypical Use
ticket_ventaSales receiptPoint of sale transactions
comandaKitchen/bar orderRestaurant orders
factura_electronicaElectronic invoiceTax invoices
stickerProduct labelInventory labels
Each document type requires a corresponding template to be configured in APM. See Template Updates for how to manage templates.

Source Reference

  • Request model: source/Core/Models/PrintJobRequest.cs:9
  • Result model: source/Core/Models/PrintJobResult.cs:7
  • WebSocket handler: source/Infraestructure/Services/WebSocketServerService.cs:478
  • Event handler: source/WorkerService/Worker.cs:30

Build docs developers (and LLMs) love