Print silently, wait for the result, cancel jobs, list jobs and avoid double printing.
Last updated
Printing is silent: no window opens and the job goes straight to the system print queue.
The simplest print
await client.compose({ queueId })
.addPdf(pdfBytes)
.printAndWait();compose() is the chained builder and .printAndWait() waits for the job to
finish. To return immediately instead:
const job = await client.compose({ queueId }).addPdf(pdfBytes).print();
console.log(job.jobId); // submitted; use this id to track itOne job, not a loop
For multiple pages or files, always use one compose() or one items array.
Do not call print() in a loop over files — that turns into N print-queue jobs,
the user sees N entries, and the paper order stops being predictable. See
composite jobs.
Waiting for the result
printAndWait() returns the terminal state:
status | Meaning |
|---|---|
completed | Paper came out |
failed | Failed, check error |
canceled | Cancelled |
const job = await client.compose({ queueId }).addPdf(bytes).printAndWait({
onStatus: (event) => updateProgress(event.status), // optional
});
if (job.status === 'failed') showError(job.error);The default timeout is 120 seconds; adjust with timeoutMs. For batches, do not
wait serially — use print() plus events.
Three levels of confidence in done
Platforms and drivers confirm "the paper came out" with different confidence, and
PrintLink does not hide that. Terminal jobs carry completionLevel:
device-reported— the printer itself reported completion, the strongest;spooler-completed— the system print queue reported completion;submitted— only the submission is confirmed; progress cannot be tracked.
Your UI wording should reflect this instead of always saying "printed".
Cancelling
await client.cancelJob(jobId); // needs the job.cancel permissionOnly possible before paper starts coming out. A job already in the printer cannot be recalled.
Listing jobs
const job = await client.getJob(jobId); // details for one job
const jobs = await client.listJobs(50); // last 50, yours onlyA job's details include the requested options, the effective options, downgrade warnings and the full status timeline — that is what to show a user asking "why is this not what I chose?".
The desktop console Jobs page shows all jobs (not just yours), supports search and filtering, can cancel queued jobs, and renders every page. Finished job artefacts are kept for 7 days by default (adjustable between 1 and 365 days).
Avoiding double printing
Network hiccups and impatient clicks can print one invoice twice. Give the job an idempotency key:
await client.compose({ queueId })
.addPdf(bytes)
.idempotencyKey(`invoice-${invoiceNo}`) // 1–128 visible ASCII characters
.printAndWait();A repeated submission with the same key is suppressed and runs once. The
suppressed submission is reported through onDuplicateSuppressed(), which is a
good moment to tell the user "this one has already been printed".
Switch to preview
Replace .printAndWait() with .preview() to let the user confirm first; the
parameters are identical. See preview.