docx_to_pdf
Convert DOCX files to PDF format by specifying the input DOCX path and the desired output PDF path.
Instructions
Convert DOCX files to PDF format
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"inputPath": "<inputPath>",
"outputPath": "<outputPath>"
},
"name": "docx_to_pdf"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputPath | Yes | Path to the input DOCX file | |
| outputPath | Yes | Path where the output PDF file should be saved |
Implementation Reference
- src/tools/docxTools.ts:112-137 (handler)The main handler function that converts DOCX to PDF using libreoffice-convert. Reads the DOCX file, converts it via LibreOffice, and writes the PDF output.
export async function convertDocxToPdf(inputPath: string, outputPath: string) { try { const ext = path.extname(inputPath).toLowerCase(); if (ext !== ".docx") { throw new Error("Input file must be a .docx file"); } if (path.extname(outputPath).toLowerCase() !== ".pdf") { throw new Error("Output file must have .pdf extension"); } const docxBuffer = await fs.readFile(inputPath); const pdfBuffer = await convertAsyncPromise(docxBuffer, ".pdf", undefined); await fs.writeFile(outputPath, pdfBuffer); return { success: true, data: `Successfully converted ${inputPath} to ${outputPath}`, }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : "Unknown error", }; } } - src/tools/docxTools.ts:35-56 (schema)Tool definition with name 'docx_to_pdf', description, and inputSchema requiring inputPath and outputPath strings.
export const DOCX_TO_PDF_TOOL: Tool = { name: "docx_to_pdf", description: "Convert DOCX files to PDF format", inputSchema: { type: "object", properties: { inputPath: { type: "string", description: "Path to the input DOCX file", }, outputPath: { type: "string", description: "Path where the output PDF file should be saved", }, }, required: ["inputPath", "outputPath"], }, }; export interface DocxToPdfArgs { inputPath: string; outputPath: string; } - src/tools/docxTools.ts:53-56 (schema)TypeScript interface DocxToPdfArgs defining inputPath and outputPath fields.
export interface DocxToPdfArgs { inputPath: string; outputPath: string; } - src/tools/docxTools.ts:101-110 (helper)Type guard function isDocxToPdfArgs that validates runtime arguments for the docx_to_pdf tool.
export function isDocxToPdfArgs(args: unknown): args is DocxToPdfArgs { return ( typeof args === "object" && args !== null && "inputPath" in args && "outputPath" in args && typeof (args as DocxToPdfArgs).inputPath === "string" && typeof (args as DocxToPdfArgs).outputPath === "string" ); } - src/index.ts:77-82 (registration)Server-side handler registration that dispatches 'docx_to_pdf' tool calls to the convertDocxToPdf function.
if (name === "docx_to_pdf") { if (!isDocxToPdfArgs(args)) { throw new Error("Invalid arguments for docx_to_pdf"); } const result = await convertDocxToPdf(args.inputPath, args.outputPath);