Skip to content

Inspect layout state over NextPDF Connect

Inspect a document’s layout state during a session so you can make positioning decisions with confidence. preview_layout — re-verified against the server tool registry, where PreviewLayoutTool exposes the protocol name preview_layout — is a read-only, idempotent query. It does not render a PDF, does not advance the cursor, and can be called any number of times. These tools are all Core: create_pdf, set_font, add_text, preview_layout, add_page, and output_pdf.

Terminal window
composer require nextpdf/server

Bind a transport. You do not need a licensed tier.

preview_layout returns the page count, current page, page dimensions, margins, and cursor position — the page’s own geometry attributes (ISO 32000-2 §7.7.3.3). Use those values to compute the remaining vertical space:

remaining = page_height - bottom_margin - cursor_y

If remaining is greater than the estimated height of your next block, continue on the current page. Otherwise, call add_page first. Because the call is read-only, it returns a normal response on every transport (PSR-18 §p2).

ToolRoleRisk tier
create_pdfOpen the sessionSafe
set_fontSet the active fontCaution
add_textWrite text, advance the cursorCaution
preview_layoutRead layout state (no mutation)Safe
add_pageAppend a page when space runs outCaution
output_pdfRender and return the PDFApproval Required / Review (base64)

The tool catalog is the source of record. The tools available to you depend on the installed tier.

  1. create_pdf (Letter portrait) → document_id.
  2. set_font (helvetica 14).
  3. add_text ×3 (justified paragraphs).
  4. preview_layout → read page_dimensions, margins, cursor_position.
  5. Compute remaining; if too small, add_page.
  6. add_text (next section).
  7. output_pdf.

Call preview_layout before any block when you are not sure it will fit. Treat the returned cursor as accurate for the last write. If you changed the font, margins, or line height since the last add_text, write a short probe and re-query before you rely on the predicted position.

  • Stale cursor after a style change. The reported position reflects the last write, not pending state changes. Re-probe if precision matters.
  • Destroyed session. preview_layout fails on a destroyed document_id. To inspect the layout after output, set destroy: false on the previous output_pdf.
  • Empty text or unknown font. Standard input-validation errors apply.

preview_layout is an inexpensive read. The profile for the produced document is structural.

The query is read-only and has no side effect. The returned coordinates are not sensitive, but treat them as session-scoped.

StatementSpecClausereference_id
A page object defines its geometry attributes.ISO 32000-2§7.7.3.3
A read-only query returns a normal transport response.PSR-18§p2

Not applicable — all tools are Core.

TransportAvailableNotes
MCP (stdio)Yespreview_layout is a tools/call.
RESTYesA safe GET-style operation.
gRPCYesUnary; idempotent.

preview_layout is Safe (read-only) and never gates. create_pdf is Safe. set_font, add_text, and add_page are Caution. output_pdf is Approval Required, downgraded to Review in base64 mode (HITL risk tiers).

Read-only inspection never gates:

{ "allowed": true }