Skip to content

Pdf Writer

The Pdf Writer component lets you turn any Markdown text into a nicely formatted PDF file.
You can give it a file name or let it pick a random one, and you can even add your own CSS to style the document.

How it Works

When you run the component it does the following:

  1. Collects the data – It takes the Markdown you provide, the optional file name, and any CSS you want to use.
  2. Formats the Markdown – The Markdown text is converted into HTML and then styled with the CSS.
  3. Creates the PDF – Using the WeasyPrint library, the styled HTML is turned into a PDF file.
  4. Returns the file – The PDF is returned as a Data object that contains the file name, the PDF content encoded in base64, and the MIME type (application/pdf).
    This file can then be used by other components in your workflow, such as a file downloader or an email sender.

No external APIs are called; everything happens locally inside Nappai.

Inputs

Mapping Mode

This component has a special mode called Mapping Mode.
When you enable this mode using the toggle switch, an additional input called Mapping Data is activated, and each input field offers you three different ways to provide data:

  • Fixed – You type the value directly into the field.
  • Mapped – You connect the output of another component to use its result as the value.
  • Javascript – You write Javascript code to dynamically calculate the value.

This flexibility allows you to create more dynamic and connected workflows.

Input Fields

  • File Content – Markdown File Content URL or File ID
    Provide the Markdown text you want to convert. It can be a direct string, a URL to a Markdown file, or a file ID from a previous component.

  • CSS Style – Style of the PDF file
    Add CSS rules to control how the PDF looks. The default style sets a clean, readable layout with Arial font and centered content.

    body {
    font-family: Arial, sans-serif;
    line-height: 1.6;
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    }
    h1, h2 {
    color: #333;
    }
  • File Name – Name of the file to be created. leave empty to use random name.
    If you leave this field blank, the component will generate a random UUID for the file name.

  • Mapping Mode – Enable mapping mode to process multiple data records in batch
    Toggle this switch to activate mapping mode.

Outputs

  • File – A Data object that contains:
    • file_name: the name of the PDF file (either the one you supplied or a random UUID).
    • base64_content: the PDF data encoded in base64, ready to be saved or sent.
    • mime_type: application/pdf.

This output can be fed into other components, such as a file downloader, an email attachment, or a storage service.

Usage Example

  1. Add the Pdf Writer component to your workflow.
  2. Set the inputs:
    • File Content: Paste your Markdown text or provide a file ID that contains Markdown.
    • CSS Style: (Optional) Leave the default or paste your own CSS to change the look.
    • File Name: Leave blank to let the component generate a random name, or type a name like Report.pdf.
  3. Run the workflow.
  4. Use the output: Connect the File output to a File Downloader component to let users download the PDF, or to an Email Sender to attach the PDF to an email.
  • File Downloader – Lets you provide the PDF file to users for download.
  • Email Sender – Can attach the PDF file to an email.
  • Markdown to Text – If you need to convert Markdown to plain text before creating a PDF, use this component first.

Tips and Best Practices

  • Test with small Markdown first to make sure the formatting looks right before processing large documents.
  • Use custom CSS to match your brand’s style guide (fonts, colors, margins).
  • Leave File Name empty if you don’t care about the file name; the component will create a unique one automatically.
  • Combine with mapping mode to generate PDFs for many records in a single run.

Security Considerations

  • The PDF content is returned as base64, so it is not exposed in plain text.
  • If the Markdown contains sensitive data, ensure that the workflow is only accessible to authorized users.
  • Large PDFs can consume memory; consider limiting the size of the Markdown input if you expect very large documents.