Skip to content

Render an HTML table over NextPDF Connect

Render structured tabular data from an HTML table string. add_table sanitizes the input with a strict DOMDocument allowlist before layout, so the output stays consistent even when the source markup varies. Use the Core tools create_pdf, add_table, and output_pdf. The table is laid out as a row/column grid (CSS Tables 3 §3.1).

Terminal window
composer require nextpdf/server

Bind a transport. The input must include a <table> root with <tr> rows and <th>/<td> cells.

add_table enforces a fixed element allowlist (table, thead, tbody, tfoot, tr, th, td, caption, b, i, u, strong, em, br, p, span). All attributes are stripped from every element — style, class, width, colspan, rowspan, id, and the rest. Any tag outside the allowlist is replaced with its text content. Cell text uses the document’s active font state, which you set with set_font before add_table. The text is emitted by text-showing operators in content-stream order (ISO 32000-2 §9.4). The layout engine, not inline CSS, decides column widths.

ToolRoleRisk tier
create_pdfOpen the sessionSafe
set_fontSet the cell text font (optional, before add_table)Caution
add_tableSanitise and lay out the tableCaution
output_pdfRender and return the PDFApproval Required / Review (base64)

The tool catalog is the catalog of record. Your available tools depend on the installed tier.

  1. create_pdf (A4 portrait, title) → document_id.
  2. add_table with a complete <table>...</table> string (header row and data rows).
  3. output_pdf → base64 or, with a file_path, a gated file write.

The cursor moves below the last rendered row, leaving room for the content that follows.

Validate the HyperText Markup Language (HTML) before you send it. Set the cell font with set_font for deterministic typography. If you rely on a default, the output font is implementation-dependent. To control which tools the host may call, restrict the registry through the security policy.

  • Empty or non-table HTML. Input with no <table> returns a no-renderable-table error.
  • Malformed markup. Unbalanced tags return a parse error, so validate the structure first.
  • Table wider than the page. Reduce columns, shorten the content, or switch to landscape orientation.
  • Overflow. A tall table flows to a new page. Check position.page in the response, or call add_page ahead of time.

A small table renders within budget, and the output is a few KB. The profile is structural. Sanitization runs in a single pass over the parsed DOM.

Attribute stripping is unconditional and cannot be bypassed. It defends against style and script injection through cell markup. No inline CSS, event handler, or javascript: URL survives. The allowlist is the trust boundary, so do not treat the rendered output as a faithful reproduction of arbitrary source styling.

StatementSpecClausereference_id
Tables are laid out as a row/column cell grid.CSS Tables 3§3.1
Text is shown by text operators in stream order.ISO 32000-2§9.4

Not applicable — every tool here is Core.

CSS support matrix excerpt (Verified-only)

Section titled “CSS support matrix excerpt (Verified-only)”

add_table does not run a general CSS engine. The only “CSS” behavior is the fixed table grid model: rows and columns come from the table structure, and the layout engine chooses the widths. Inline styling is unsupported by design because attributes are stripped. For engine-level (non-Connect) CSS coverage, see the project CSS support matrix.

add_table parses the supplied markup into a DOM once and lays it out in a single pass. It does not reflow against external stylesheets. A table that overflows the page advances to the next page instead of reflowing retroactively.

Very large tables hold the parsed DOM and laid-out cells in memory for the whole call. Split large datasets across multiple add_table calls to stay within the peak-memory budget.

TransportAvailableNotes
MCP (stdio)YesLarge HTML inflates the stdio frame.
RESTYesSend the HTML in the request body.
gRPCYesUnary; message-size limits apply.

create_pdf is Safe; set_font and add_table are Caution; output_pdf is Approval Required, downgraded to Review in base64 mode. File output stays Approval Required. See output-approval.

Base64 output:

{ "allowed": true }

File output returns the challenge envelope that output-approval documents.