PrintBase
  • Product
  • Pricing
  • Docs
  • Resources
PrintBase/Guides/Print from your language or framework

Print a PDF from Node.js to a printer in another place

From Node.js, base64 a PDF and POST it to the print-jobs API. The printer is attached to a computer running the agent, not to your server.

For Node.js backends that generate invoices or labels

Overview

Node.js on a cloud VM has no printer. Shelling out to lp only works when the printer is installed on that same machine. The print API is one HTTPS call from any Node process that can reach api.printbase.cloud.

Read the PDF from disk or from your generator, base64 it, and send content_type pdf with printer_code. If the file is already on a public HTTPS URL, send content_url and skip the base64. The official site lists a Node SDK; this sample uses fetch against the public REST shape those clients wrap, which is the shape in the API docs.

Keep PRINTBASE_API_KEY in the environment. A 201 response is queued, not paper. Poll the job id or use a paid-plan webhook.

Integration steps

  1. 01

    Create an API key on the server

    Use an API key (pb_live_…) in the process environment. Authorization is Bearer. Do not ship the key to browsers or mobile apps.

  2. 02

    Install the agent beside the printer

    Windows, macOS, or Linux. GET /v1/printers and keep the numeric code.

  3. 03

    POST /v1/print-jobs

    content_type is pdf or raw. Send exactly one of content (standard base64) or content_url.

  4. 04

    Reuse the idempotency key on retry

    A new key means a second physical print. HTTP 409 means the same key was reused with a different body.

  5. 05

    Read the job before you tell the user

    GET /v1/print-jobs/{id}. Paid plans can also receive print_job.completed and print_job.failed webhooks.

Node.js

// Node.js: invoice PDF
const res = await fetch('https://api.printbase.cloud/v1/print-jobs', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.PRINTBASE_API_KEY}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': invoiceId,
  },
  body: JSON.stringify({
    printer_code: Number(process.env.PRINTER_CODE),
    content_type: 'pdf',
    content: pdf.toString('base64'),
    copies: 1,
  }),
});
if (!res.ok) throw new Error(`PrintBase ${res.status}: ${await res.text()}`);
const job = await res.json();
// { id: "job_abc", status: "queued" }

Details for this setup

Large PDFs

Prefer content_url when the agent can download the file. Base64 grows the body by about a third. The URL must be http or https and reachable without your user's cookies.

Windows PDF printing

The agent asks a PDF application to print. If none is registered, the error mentions Adobe Reader or SumatraPDF as examples of apps that support the shell print verb.

Questions

Do I have to install a native Node module?

No. fetch or any HTTP client is enough. The marketing site lists an official Node SDK; its requests use this same endpoint and JSON.

Can this print a printer on the Node host?

If the agent is installed there and the OS sees the printer, yes. A typical container host has neither.

How do I avoid duplicate invoices?

Pass an Idempotency-Key of the invoice id. Retries reuse it.

What about ZPL from Node?

Use content_type raw. That is a different page: node-js-zpl.

Related guides

  • Print ZPL labels from Node.js

    Build a ZPL string in Node.js and send it as raw base64. The agent does not render the label; the printer does.

  • Print shipping labels from a Next.js route

    Print from a Next.js route handler on the server. Do not call the API from a client component. The key stays in the server environment.

  • Print a PDF from Python

    Use the Python standard library to POST a base64 PDF. No extra print package is required. The agent prints it on the computer you chose.

  • Print a PDF from Go

    Read a PDF in Go and post it as base64. Use content_url if the object store link is public. No CGO PDF library is required to transport the file.

Free plan: 100 jobs a month on one computer, no card.

Create a free accountRead the API docs
PrintBase

PrintBase connects your applications to physical printers anywhere - securely, reliably, and in real time.

Product
Receipt PrintingLabel PrintingDashboardDevicesWebhooks
Resources
DocsBlogStatusAPI ReferenceDownloadPrintBase vs PrintNodePrintNode PricingFAQ
Guides
All guidesIntegrationsPrintersCode samplesComparisonsUse casesTroubleshooting
Company
ContactSecurityPrivacy

© 2026 Aveniq Technologies OÜ. All rights reserved. PrintBase is a service of Aveniq Technologies OÜ.

PrivacyTermsRefunds