JSON to PDF icon

JSON to PDF

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

Single PDF

AI-generated

Overview

This node converts JSON or Markdown input into a PDF document. It supports two main operations:

  • Single PDF: Converts a single string or an object containing a string ({ data }) into a PDF, splitting pages based on a specified keyword.
  • Generate E-book: Creates a multi-chapter e-book PDF from an array of chapters, each with a title and content, optionally including a table of contents.

This node is useful for automating the generation of PDF reports, documentation, e-books, or any text-based content that needs to be formatted as a PDF. For example, you can convert Markdown notes into a nicely formatted PDF or compile multiple chapters into an e-book with a table of contents.

Properties

Name Meaning
Raw Input The source content to convert. For Single PDF: either a string or an object { data } with string content. For E-book: an object { title, data[] } where data is an array of chapters. Each chapter has a title and content.
Filename The name of the output PDF file (default: output.pdf).
Font The font used in the PDF. Options: Helvetica, Times-Roman, Courier, Helvetica-Bold.
Font Size The base font size for the text (default: 12).
Line Spacing The line spacing multiplier (default: 1.15).
Page-break Keyword (Single PDF only) A string keyword that triggers a page break when found at the start of a line (default: ## Chapter).
Include TOC (E-book only) Whether to include a Table of Contents (default: true).
TOC Title (E-book only, if TOC included) The title text for the Table of Contents (default: Table of Contents).
Chapter Title Style (E-book only) How chapter titles are displayed: New page at title (each chapter starts on a new page) or Inline (titles inline with content).

Output

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

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

No additional JSON fields are output.

Dependencies

  • Uses the pdfkit library to generate PDFs.
  • Uses markdown-it to parse and render inline Markdown syntax.
  • Uses Node.js streams to handle PDF data output.

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 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 input for E-book operation is not an array or an object with a data array property. Provide the correct structure with chapters.

  • PDF output is empty or malformed
    Check that the input text is correctly formatted and that the page-break keyword (for Single PDF) matches the intended lines.

  • Font or styling issues
    Verify that the selected font is supported and that font size and line spacing values are reasonable.

Links and References

Discussion