render_hwp_all_pages
Render each page of HWP/HWPX documents to SVG files, storing them in a specified directory.
Instructions
Render every page of an HWP/HWPX as SVG files in a directory. Args: file_path, output_dir (default _pages/), max_pages (optional limit).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| output_dir | No | ||
| max_pages | No |
Implementation Reference
- src/tools/render.ts:49-84 (handler)Main handler for render_hwp_all_pages: opens an HWP document, determines output directory (default: <file>_pages/), iterates over pages up to optional max_pages, renders each page as SVG, writes to disk, and returns a summary.
export async function renderHwpAllPages(args: RenderAllArgs): Promise<string> { let doc; try { doc = await openDocument(args.file_path); } catch (e) { return (e as Error).message; } try { const pages = getPageCount(doc); if (pages === 0) return "(렌더할 페이지가 없습니다 / no pages)"; const baseName = basename(args.file_path, extname(args.file_path)); const outDir = args.output_dir ? resolve(args.output_dir) : resolve(dirname(args.file_path), `${baseName}_pages`); mkdirSync(outDir, { recursive: true }); const limit = Math.min(args.max_pages ?? pages, pages); const saved: string[] = []; for (let i = 0; i < limit; i++) { const svg = renderPageSvg(doc, i); const fname = `page_${String(i + 1).padStart(3, "0")}.svg`; writeFileSync(join(outDir, fname), svg); saved.push(fname); } return [ `${saved.length}/${pages} 페이지 SVG 저장 (rendered ${saved.length}/${pages} pages):`, `저장 위치 (output): ${outDir}`, "", ...saved.slice(0, 10).map((s) => ` - ${s}`), saved.length > 10 ? ` ... and ${saved.length - 10} more` : "", ].filter(Boolean).join("\n"); } catch (e) { return `렌더 오류 (render error): ${(e as Error).message}`; } finally { closeDocument(doc); } } - src/tools/render.ts:16-20 (schema)Type definition for the input arguments of renderHwpAllPages: file_path (required), output_dir (optional), max_pages (optional limit).
export interface RenderAllArgs { file_path: string; output_dir?: string; max_pages?: number; } - src/server.ts:203-215 (registration)Tool registration entry in the TOOLS array defining the tool name, description, and input JSON schema (file_path required, output_dir and max_pages optional).
{ name: "render_hwp_all_pages", description: "Render every page of an HWP/HWPX as SVG files in a directory. Args: file_path, output_dir (default <file>_pages/), max_pages (optional limit).", inputSchema: { type: "object", properties: { file_path: { type: "string" }, output_dir: { type: "string" }, max_pages: { type: "number" }, }, required: ["file_path"], }, - src/server.ts:519-519 (registration)Handler mapping in the HANDLERS object linking the tool name 'render_hwp_all_pages' to the renderHwpAllPages function.
render_hwp_all_pages: renderHwpAllPages, - src/core/document.ts:251-253 (helper)Helper function that delegates to the underlying @rhwp/core library's renderPageSvg method to render a single page as SVG.
export function renderPageSvg(doc: HwpDocument, pageNum: number): string { return doc.renderPageSvg(pageNum); }