Skip to content

Control fonts and text styling over NextPDF Connect

Build a document with multiple text styles by switching fonts between text blocks. set_font sets the active typeface, style, and size. That state applies to each following add_text call until you change it. You need create_pdf, set_font, add_text, and output_pdf — all Core tools. Text state parameters control glyph rendering (ISO 32000-2 §9).

Terminal window
composer require nextpdf/server

Bind a transport. You can use three built-in font families without adding font files: helvetica, times, and courier.

set_font takes family, style ("", "B", "I", "BI", "U"), and size. The font you set applies to every later add_text call until you call set_font again. There is no automatic reset. When add_text includes font_size, that value overrides the active size for that single call only. The set_font size returns for the next call. Text is emitted by text-showing operators in content-stream order (ISO 32000-2 §9.4). add_text has no colour parameter. Text colour comes from the document’s graphics-state ink colour.

ToolRoleRisk tier
create_pdfOpen the sessionSafe
set_fontSet the active typeface/style/sizeCaution
add_textWrite text in the active fontCaution
output_pdfRender and return the PDFApproval Required / Review (base64)

The tool catalog is the catalog of record. The tools you can use depend on the installed tier.

  1. create_pdf (A4 portrait) → document_id.
  2. set_font (helvetica, B, 24) then add_text (title, centered).
  3. set_font (helvetica, "", 12) then add_text (justified body).
  4. set_font (courier, I, 10) then add_text (a code snippet).
  5. output_pdf.

Set the font explicitly before each block where typography matters. Never rely on inherited state across logical sections. Use the per-call font_size override only for one-off emphasis, because it does not persist. Build the document section by section, and verify that each add_text returns a position.

  • Unknown family. Anything outside helvetica/times/courier (for example arial) is rejected.
  • Empty family. family must be a non-empty string.
  • Invalid style. Use the uppercase codes. "bold" is rejected.
  • Non-positive size. size must be a positive number.
  • Per-call size is temporary. It does not change the set_font state.

Built-in fonts add negligible weight, and output is a few KB. The profile is structural.

Base64 mode has no filesystem side effect. Built-in fonts do not ingest external font files, so this recipe has no font-parsing attack surface.

StatementSpecClausereference_id
Text is shown by text operators in stream order.ISO 32000-2§9.4
Text-state parameters govern glyph rendering.ISO 32000-2§9

Not applicable — all tools are Core.

TransportAvailableNotes
MCP (stdio)Yestools/call per tool.
RESTYesOne operation per tool.
gRPCYesUnary per tool.

create_pdf Safe; set_font/add_text Caution; output_pdf Approval Required, downgraded to Review in base64 mode (HITL risk tiers).

Base64 output:

{ "allowed": true }