Preview
Open a preview window so the user confirms before paper comes out, and change paper or layout from the window or your own code.
Last updated
Preview opens PrintLink's preview window so the user can see what is about to print. What the window shows is what the printer receives — confirming does not re-render, which rules out preview-versus-print mismatches by construction.
const session = await client
.compose({ queueId })
.paper('A4')
.addPdf(bytes)
.preview();
console.log(session.pageCount); // how many pages
console.log(session.warnings); // option downgrades, if anyRequires the job.preview permission (granted by default). PrintLink opens the
window and the user prints from there; your page can also drive it:
await client.previewPrint(session.previewSessionId); // print what is previewed
await client.previewClose(session.previewSessionId); // close itWhat is in the window
- Thumbnails on the left, one per output page, with a source badge for mixed content (image / PDF / web page / template).
- Status bar, e.g.
12 output pages · 4 sources · A4 210×297 mm. - Options panel: paper, copies, duplex, colour, quality — changing one takes effect immediately and re-renders the preview.
- Canvas actions when an image page is selected: drag, scale, rotate, flip and "Reset this image".
Output pages and source items are different things: output pages are the
pages of the final artefact (1 to pageCount), while source items are the pieces
you added. A 3-page PDF in a mixed job is 1 source item covering 3 output pages.
Badges and the status bar's "sources" refer to the latter.
Changing the preview from code
The window handles user changes on its own; your page usually does not need to
intervene. When it does, use previewUpdate:
await client.previewUpdate({
previewSessionId: session.previewSessionId,
options: { paper: { id: 'A5' } }, // options is replaced, not merged
});Page by page
If you build your own preview UI instead of using the desktop window, pull rasters one page at a time:
const page = await client.previewGetPage(session.previewSessionId, 0);
// page.pngBase64 the page bitmap
// page.origin where it came from: { itemIndex, kind, itemPageIndex }
// page.pageLayout the layout actually used, always presentsession.source.items maps each source to its output pages
(outputPageStart / outputPageCount), which is exactly what you need for a
caption like "page 3 · PDF 2/3".
Permission
previewGetPage is restricted to the trusted local UI — web pages cannot
call it. From a page, use preview() and let PrintLink open its own preview
window.
Closing and expiry
- Closing the window or pressing Esc hides it first and recycles the session asynchronously; it never lands on an "expired preview" screen.
- A session that sits unused expires, after which
previewPrint/previewGetPagereturnPREVIEW_NOT_FOUND. previewClosereleases it eagerly, which is tidier when a page navigates away.