On this page
Sommatic Docs
Open portal

Convert to PDF

Generic string-to-PDF converter.

View as Markdown
Open in
Data Available data.convert.to.pdf Version 1.0.0 Execution: sync

Renders plain text, Markdown or HTML into a PDF with PDFKit and returns it base64-encoded, with an optional title, data blocks, page header, footer, watermark and page numbers.

Supported input types

  • text — rendered as-is, plain wrap.
  • markdown — parsed with marked; renders headings, paragraphs, bold/italic/code, ordered/unordered lists, blockquotes, links, horizontal rules.
  • html — parsed with htmlparser2; renders h1..h6, p, strong/b, em/i, code/pre, ul/ol/li, blockquote, a, hr, br. Non-supported tags render as text. Images (<img>) are dropped — carry them as separate attachments if needed.

Page decoration (all optional)

  • metadata — object rendered as a key/value block above the body (e.g. From/To/Subject/Date for an email; Contract/Client/Date for a document).
  • document_header — text painted at the top of every page (e.g. institutional header).
  • document_footer — text painted at the bottom of every page (e.g. legal footer).
  • watermark — rotated background text with configurable opacity.
  • page_numbers — appends "Página N de M" to the bottom-right of every page.

Design constraints

  • Pure input → output. No blob download, no external I/O, no Cosmos/Mongo touch. Fully testable in isolation.
  • Reusable for any string → PDF scenario (email body, contracts, manuals, logs). Not coupled to any specific domain.
  • Uses pdfkit (JS pure, no chromium). Fast and lightweight; suitable for envelopes.

How it works

  1. Resolves the config. content comes from the config, or from content in the incoming payload; an empty value fails the node.
  2. Reads the layout: input_type (default text, case-insensitive), filename (default document.pdf), page_size (default A4) and page_margin (default 50 points). A header adds 30 points to the top margin; a footer or page numbers add 30 points to the bottom margin.
  3. Draws the optional blocks before the body, in this order: title (with subtitle), traceability and metadata. When any of them is present, a fixed bold label precedes the body.
  4. Draws the body: text as is; markdown through the marked lexer (headings, paragraphs, bold, italic, inline code, links, lists, code blocks, blockquotes, rules); html through htmlparser2 (h1–h6, p, pre, blockquote, li, hr, br, b/strong, i/em, code, a).
  5. Paints on every page the watermark, document_header, document_footer and, with page_numbers, a bottom-right page counter.
  6. Returns { pdf_base64, filename, size_bytes, input_type, format: "pdf" } through out.

In a workflow

The node as it appears in a workflow file (draft_nodes[]), and the envelope of a successful run.

{
  "node_id": "node-render-summary",
  "label": "Render summary PDF",
  "operator_slug": "data.convert.to.pdf",
  "operator_version": "1.0.0",
  "config": {
    "content": "{{ $json.summary_markdown }}",
    "input_type": "markdown",
    "filename": "case-summary.pdf",
    "page_size": "A4",
    "page_numbers": true,
    "document_footer": {
      "text": "Confidential. Generated by an automated workflow."
    }
  }
}

Configuration

content string Required

The source content (plain text, Markdown, or HTML) to convert into a PDF.

input_type string Optional

How to interpret the content string.

Default: text

Allowed values: textmarkdownhtml

filename string Optional

Logical filename for the produced PDF (used in metadata and echoed in output).

Default: document.pdf

page_size string Optional

Default: A4

Allowed values: A4Letter

page_margin number Optional

Uniform margin in points (72pt = 1in).

Default: 40

metadata object Optional

Key/value pairs rendered as a small table above the body.

document_header object Optional

Text painted at the top of every page.

text string Optional
style object Optional
font_size number Optional

Font size in points.

bold boolean Optional

Whether the text is bold.

color string Optional

Text color as hex (e.g. "#666666").

align string Optional

Horizontal alignment.

Allowed values: leftcenterright

watermark object Optional

Rotated background text painted on every page.

text string Optional
opacity number Optional

Opacity 0..1 (default 0.06).

rotation number Optional

Rotation in degrees (default 45).

color string Optional

Hex color (default "#000000").

font_size number Optional

Watermark font size (default 60pt).

page_numbers boolean Optional

If true, prints "Página N de M" on the bottom-right of every page.

Default: false

Its configuration shows the shared execution settings, but this node does not apply retries (retryOnFail, maxTries) yet. continueOnFail is not applied by any node.

Behaviour in the code

What the implementation does with these keys beyond what the schema says.

page_margin
The code default is 50 points, not the 40 shown in the schema. Non-numeric values fall back to 50.
title Read by the code, not declared
Not declared. Centered bold title (14 pt) with an optional subtitle (also undeclared) and a rule below.
traceability Read by the code, not declared
Not declared. Object of key/value pairs drawn as a small monospaced block; null or empty values are skipped. metadata works the same way with a regular font.
watermark
Code defaults: opacity 0.06, rotation -30 degrees, font_size 40, color #000000 (the schema text says 45 degrees and 60 pt).
document_header
text plus style (align, color, font_size default 8, bold). Long text is cut with an ellipsis: one line in the header, two lines in document_footer.

Output ports

out default

The PDF was generated. size_bytes is the raw PDF size before base64.

Data
{
  "pdf_base64": "JVBERi0xLjMKJf////8KNyAwIG9iago8PAovVHlwZSAvUGFnZQo...",
  "filename": "case-summary.pdf",
  "size_bytes": 18432,
  "input_type": "markdown",
  "format": "pdf"
}
error

content is empty or PDFKit failed.

Data
{
  "error": "content is required"
}

In expressions

What a later node can read from this node's output with $("Convert to PDF").item.json.<path> (write your node's label instead of Convert to PDF). Editor marks the paths the workflow editor suggests under Previous Nodes (the output contract); Worker marks the paths the worker really returns through out, from the output shown in Ports.

ExpressionEditorWorker
$("Convert to PDF").item.json.pdf_base64string= "JVBERi0xLjMKJf////8KNyAwIG9iago8PAovVHlwZSAv…"PDF binary base64-encoded (fits Link Loom envelope constraints).
$("Convert to PDF").item.json.filenamestring= "case-summary.pdf"
$("Convert to PDF").item.json.size_bytesnumber= 18432Raw PDF size in bytes (pre-base64).
$("Convert to PDF").item.json.input_typestring= "markdown"Echo of the input_type used.
$("Convert to PDF").item.json.formatstring= "pdf"Always 'pdf'.

Errors

Message Port Cause and fix
content is required error No content in the config or in the payload. Map it, for example {{ $json.summary_markdown }}.
Cannot read properties of undefined (reading '0') error page_size is not a size PDFKit knows. Use A4 or Letter.

Input contract

content string Required
input_type string Optional

Output contract

pdf_base64 string Optional

PDF binary base64-encoded (fits Link Loom envelope constraints).

filename string Optional
size_bytes number Optional

Raw PDF size in bytes (pre-base64).

input_type string Optional

Echo of the input_type used.

format string Optional

Always 'pdf'.

Contracts (JSON Schema)

The definition exactly as the orchestrator declares it. All is the whole *.definition.js; compare it with the sections above to spot differences between the documentation and the schema. Use it to validate a node before you publish.

{
  "slug": "data.convert.to.pdf",
  "name": "Convert to PDF",
  "category": "data",
  "version": "1.0.0",
  "description": "Generic string-to-PDF converter. Accepts plain text, Markdown, or HTML and produces a PDF binary encoded as base64 in the envelope (Link Loom envelopes do not transport raw Buffers between nodes).\n\n**Supported input types**\n- `text` — rendered as-is, plain wrap.\n- `markdown` — parsed with `marked`; renders headings, paragraphs, bold/italic/code, ordered/unordered lists, blockquotes, links, horizontal rules.\n- `html` — parsed with `htmlparser2`; renders `h1..h6`, `p`, `strong/b`, `em/i`, `code/pre`, `ul/ol/li`, `blockquote`, `a`, `hr`, `br`. Non-supported tags render as text. Images (`<img>`) are dropped — carry them as separate attachments if needed.\n\n**Page decoration (all optional)**\n- `metadata` — object rendered as a key/value block above the body (e.g. From/To/Subject/Date for an email; Contract/Client/Date for a document).\n- `document_header` — text painted at the top of every page (e.g. institutional header).\n- `document_footer` — text painted at the bottom of every page (e.g. legal footer).\n- `watermark` — rotated background text with configurable opacity.\n- `page_numbers` — appends \"Página N de M\" to the bottom-right of every page.\n\n**Design constraints**\n- Pure input → output. No blob download, no external I/O, no Cosmos/Mongo touch. Fully testable in isolation.\n- Reusable for any `string → PDF` scenario (email body, contracts, manuals, logs). Not coupled to any specific domain.\n- Uses pdfkit (JS pure, no chromium). Fast and lightweight; suitable for envelopes.",
  "capabilities": [
    "pdf",
    "convert",
    "html-to-pdf",
    "markdown-to-pdf",
    "text-to-pdf"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "content"
    ],
    "properties": {
      "content": {
        "type": "string",
        "title": "Content",
        "format": "textarea",
        "description": "The source content (plain text, Markdown, or HTML) to convert into a PDF."
      },
      "input_type": {
        "type": "string",
        "enum": [
          "text",
          "markdown",
          "html"
        ],
        "default": "text",
        "title": "Input Type",
        "description": "How to interpret the content string."
      },
      "filename": {
        "type": "string",
        "default": "document.pdf",
        "title": "Filename",
        "description": "Logical filename for the produced PDF (used in metadata and echoed in output)."
      },
      "page_size": {
        "type": "string",
        "enum": [
          "A4",
          "Letter"
        ],
        "default": "A4",
        "title": "Page Size"
      },
      "page_margin": {
        "type": "number",
        "default": 40,
        "title": "Page Margin (points)",
        "description": "Uniform margin in points (72pt = 1in)."
      },
      "metadata": {
        "type": "object",
        "title": "Metadata Block",
        "description": "Key/value pairs rendered as a small table above the body.",
        "additionalProperties": {
          "type": "string"
        }
      },
      "document_header": {
        "type": "object",
        "title": "Page Header",
        "description": "Text painted at the top of every page.",
        "properties": {
          "text": {
            "type": "string"
          },
          "style": {
            "type": "object",
            "properties": {
              "font_size": {
                "type": "number",
                "description": "Font size in points."
              },
              "bold": {
                "type": "boolean",
                "description": "Whether the text is bold."
              },
              "color": {
                "type": "string",
                "description": "Text color as hex (e.g. \"#666666\")."
              },
              "align": {
                "type": "string",
                "enum": [
                  "left",
                  "center",
                  "right"
                ],
                "description": "Horizontal alignment."
              }
            }
          }
        }
      },
      "document_footer": {
        "type": "object",
        "title": "Page Footer",
        "description": "Text painted at the bottom of every page (e.g. legal disclaimer).",
        "properties": {
          "text": {
            "type": "string"
          },
          "style": {
            "type": "object",
            "properties": {
              "font_size": {
                "type": "number",
                "description": "Font size in points."
              },
              "bold": {
                "type": "boolean",
                "description": "Whether the text is bold."
              },
              "color": {
                "type": "string",
                "description": "Text color as hex (e.g. \"#666666\")."
              },
              "align": {
                "type": "string",
                "enum": [
                  "left",
                  "center",
                  "right"
                ],
                "description": "Horizontal alignment."
              }
            }
          }
        }
      },
      "watermark": {
        "type": "object",
        "title": "Watermark",
        "description": "Rotated background text painted on every page.",
        "properties": {
          "text": {
            "type": "string"
          },
          "opacity": {
            "type": "number",
            "description": "Opacity 0..1 (default 0.06)."
          },
          "rotation": {
            "type": "number",
            "description": "Rotation in degrees (default 45)."
          },
          "color": {
            "type": "string",
            "description": "Hex color (default \"#000000\")."
          },
          "font_size": {
            "type": "number",
            "description": "Watermark font size (default 60pt)."
          }
        }
      },
      "page_numbers": {
        "type": "boolean",
        "default": false,
        "title": "Show Page Numbers",
        "description": "If true, prints \"Página N de M\" on the bottom-right of every page."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": {
    "type": "object",
    "required": [
      "content"
    ],
    "properties": {
      "content": {
        "type": "string"
      },
      "input_type": {
        "type": "string"
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "pdf_base64": {
        "type": "string",
        "description": "PDF binary base64-encoded (fits Link Loom envelope constraints)."
      },
      "filename": {
        "type": "string"
      },
      "size_bytes": {
        "type": "number",
        "description": "Raw PDF size in bytes (pre-base64)."
      },
      "input_type": {
        "type": "string",
        "description": "Echo of the input_type used."
      },
      "format": {
        "type": "string",
        "description": "Always 'pdf'."
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "PDF",
      "description": "PDF generated successfully.",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Conversion failed.",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "sync",
  "required_resources": [],
  "tags": [
    "pdf",
    "convert",
    "html",
    "markdown",
    "text",
    "render"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}

Execution

Execution
sync
Stateful
No
Retries (retryOnFail)
No
Capabilities
pdfconverthtml-to-pdfmarkdown-to-pdftext-to-pdf
Tags
pdfconverthtmlmarkdowntextrender

Notes and limits

  • Uses the PDF standard fonts Helvetica and Courier: characters outside their Latin set (for example Chinese, Japanese or emoji) are not rendered correctly.
  • Fixed labels are in Spanish: "Trazabilidad", "Encabezados del correo", "Contenido del correo" and "Página N de M".
  • Images are ignored, Markdown tables are not drawn and HTML tables are flattened into plain paragraphs.
  • The whole PDF is held in memory and travels base64-encoded in the payload (about 4/3 of its size). The incoming payload is replaced by the result.
  • The worker does not set ok (the example shows true); the engine routes only by port.

Reviewed against the orchestrator code · 31e874b · 2026-11-26

Install agent tools

Give your coding agent the official Sommatic AI docs: skills, the docs MCP server and Markdown pages, so it never has to scrape the site.

Skills only. They do not update by themselves; run it again to refresh.

npx skills add https://docs.sommatic.ai
How agents read these docs