JSON to PDF icon

JSON to PDF

Convert JSON / Markdown into a PDF (single page or e-book)

Generate E-book

AI-generated

Overview

This node converts JSON or Markdown input into a PDF document. It supports two main operations: creating a single-page PDF from raw text or generating a multi-chapter e-book with optional table of contents (TOC). This is useful for automating the creation of PDF reports, documentation, or e-books directly from structured data or markdown content.

Common scenarios:

  • Generating a PDF report from markdown notes or JSON content.
  • Creating an e-book with multiple chapters and a TOC from an array of chapter data.
  • Automating PDF generation workflows where input content is dynamically provided as JSON or markdown.

Example:

  • Inputting a JSON object representing an e-book with title and chapters, then outputting a formatted PDF e-book with chapter titles and a clickable TOC.
  • Converting a markdown string with page breaks into a styled single PDF document.

Properties

Name Meaning
Operation Choose between "Single PDF" (one continuous document) or "Generate E-book" (multi-chapter PDF).
Raw Input For Single PDF: a string or { data } object containing markdown text.
For E-book: an object { title, data[] } where data is an array of chapters with titles and content.
Filename The name of the output PDF file (default: output.pdf).
Font Font family to use in the PDF. Options: Helvetica, Times-Roman, Courier, Helvetica-Bold.
Font Size Base font size for the PDF text (default: 12).
Line Spacing Line spacing multiplier for text lines (default: 1.15).
Page-break Keyword (Single PDF only) String keyword that triggers a new page when found at the start of a line (default: ## Chapter).
Include TOC (E-book only) Whether to include a Table of Contents page (default: true).
TOC Title (E-book only, if TOC included) Title text for the Table of Contents page (default: "Table of Contents").
Chapter Title Style (E-book only) How chapter titles are displayed:
- New page at title
- Inline (default: New page at title).

Output

The node outputs a single item with binary data representing the generated PDF file:

  • binary.data: Contains the PDF file data as a buffer.
  • binary.data.mimeType: Always "application/pdf".
  • binary.data.fileName: The filename specified by the user.
  • binary.data.fileExtension: "pdf".
  • binary.data.fileSize: Size of the PDF file in bytes.

No additional JSON fields are output; the main result is the PDF binary data.

Dependencies

  • Uses the pdfkit library to generate PDFs.
  • Uses markdown-it to parse and render markdown inline formatting.
  • Uses Node.js streams and get-stream to collect the PDF output buffer.

No external API keys or services are required. All processing is done locally within the node.

Troubleshooting

  • Error: "Single PDF expects string or { data }"
    Occurs if the input for the single PDF operation is not a string or an object with a string data property. Ensure the input matches one of these formats.

  • Error: "E-book expects array or { title, data }"
    Happens if the e-book input is not an array or an object with a data array property. Provide the e-book content as an array of chapters or an object with title and data array.

  • PDF output is empty or malformed
    Check that the input markdown or JSON content is correctly formatted. Invalid markdown or missing chapter content can cause blank pages.

  • Page breaks not working in Single PDF
    Verify the "Page-break Keyword" matches exactly the start of lines where you want new pages.

Links and References

Discussion