Skip to main content
Glama
Theorhd
by Theorhd

generate_pdf_from_text

Convert plain text content into PDF documents with customizable formatting options like fonts, margins, and file naming. Automatically saves to specified directories for organized document creation.

Instructions

Generate a PDF from plain text using PDFKit

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
text_contentYesText content to convert to PDF
output_filenameYesName of the output PDF file (without path)
output_dirNoOutput directory (optional, defaults to Downloads)/root/Downloads
optionsNoPDF formatting options

Implementation Reference

  • The handler logic for executing the 'generate_pdf_from_text' tool. It uses PDFKit to generate a PDF from text content, applies formatting options, validates and saves to the output path, and returns a success message.
    case "generate_pdf_from_text": {
      const { text_content, output_filename, output_dir = DEFAULT_OUTPUT_DIR, options = {} } = args as any;
      
      const outputPath = validateOutputPath(path.join(output_dir, output_filename));
      
      await fs.mkdir(path.dirname(outputPath), { recursive: true });
      
      const doc = new PDFDocument({
        margins: options.margins || { top: 50, left: 50, right: 50, bottom: 50 }
      });
      
      const stream = createWriteStream(outputPath);
      doc.pipe(stream);
      
      doc.font(options.font || 'Helvetica')
         .fontSize(options.fontSize || 12);
      
      doc.text(text_content);
      
      doc.end();
      
      return new Promise((resolve) => {
        stream.on('finish', () => {
          resolve({
            content: [
              {
                type: "text",
                text: `PDF successfully generated from text: ${outputPath}`
              }
            ]
          });
        });
      });
    }
  • The tool definition including name, description, and detailed inputSchema with properties, defaults, and required fields for the generate_pdf_from_text tool.
    {
      name: "generate_pdf_from_text",
      description: "Generate a PDF from plain text using PDFKit",
      inputSchema: {
        type: "object",
        properties: {
          text_content: {
            type: "string",
            description: "Text content to convert to PDF"
          },
          output_filename: {
            type: "string",
            description: "Name of the output PDF file (without path)"
          },
          output_dir: {
            type: "string", 
            description: "Output directory (optional, defaults to Downloads)",
            default: DEFAULT_OUTPUT_DIR
          },
          options: {
            type: "object",
            description: "PDF formatting options",
            properties: {
              fontSize: { type: "number", default: 12 },
              font: { type: "string", default: "Helvetica" },
              margins: {
                type: "object",
                properties: {
                  top: { type: "number", default: 50 },
                  left: { type: "number", default: 50 },
                  right: { type: "number", default: 50 },
                  bottom: { type: "number", default: 50 }
                }
              }
            }
          }
        },
        required: ["text_content", "output_filename"]
      }
    },
  • index.ts:175-177 (registration)
    Registration of the ListToolsRequestSchema handler, which returns the list of available tools including 'generate_pdf_from_text'.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return { tools };
    });
  • Helper function used by the tool handler to validate that the output path is within allowed user directories for security.
    function validateOutputPath(outputPath: string): string {
      const resolvedPath = path.resolve(outputPath);
      const isAllowed = ALLOWED_DIRS.some(allowedDir => 
        resolvedPath.startsWith(path.resolve(allowedDir))
      );
      
      if (!isAllowed) {
        throw new Error(`Output path must be within allowed directories: ${ALLOWED_DIRS.join(", ")}`);
      }
      
      return resolvedPath;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool generates a PDF but doesn't mention critical behaviors: whether it overwrites existing files, requires specific permissions, handles errors, or what the output looks like (e.g., file path). For a tool that creates files, this lack of transparency about side effects and outcomes is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence: 'Generate a PDF from plain text using PDFKit'. It's front-loaded with the core purpose, uses no unnecessary words, and clearly communicates the essential action. Every part of the sentence earns its place by specifying the output (PDF), input (plain text), and method (PDFKit).

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (4 parameters including nested objects, no annotations, no output schema), the description is incomplete. It doesn't address behavioral aspects like file creation side effects, error handling, or output details. For a tool that generates files, more context is needed about what happens after invocation, especially without annotations or output schema to fill these gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional parameter information beyond what's in the schema. It doesn't explain parameter interactions, provide examples, or clarify semantics like what 'plain text' entails versus HTML/markdown. The baseline score of 3 reflects adequate schema coverage without description enhancement.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Generate a PDF from plain text using PDFKit'. It specifies the verb ('Generate'), resource ('PDF'), and source format ('plain text'), making the action unambiguous. However, it doesn't explicitly differentiate from sibling tools like generate_pdf_from_html or generate_pdf_from_markdown, which handle different input formats.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools (generate_pdf_from_html, generate_pdf_from_markdown, read_pdf) or specify scenarios where plain text conversion is preferred over other formats. There's also no information about prerequisites or constraints, leaving usage context unclear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Theorhd/Pdftools-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server