### Install kordoc Source: https://github.com/chrisryugj/kordoc/blob/main/README-EN.md Install the kordoc package using npm. PDF support can be optionally installed. ```bash npm install kordoc # PDF support (optional) npm install pdfjs-dist ``` -------------------------------- ### Kordoc CLI Usage Examples Source: https://github.com/chrisryugj/kordoc/blob/main/README-EN.md Demonstrates various ways to use the Kordoc CLI for document conversion and manipulation. Options include specifying output files, batch processing, format selection, page ranges, and form filling. ```bash npx kordoc document.hwpx # stdout ``` ```bash npx kordoc document.hwp -o output.md # save to file ``` ```bash npx kordoc *.pdf -d ./converted/ # batch convert ``` ```bash npx kordoc report.hwpx --format json # JSON with blocks + metadata ``` ```bash npx kordoc report.hwpx --pages 1-3 # page range ``` ```bash npx kordoc fill form.hwpx -f 'name=John,addr=Seoul' -o filled.hwpx # auto-fill form ``` ```bash npx kordoc fill form.hwpx -j values.json -o filled.hwpx # fill from JSON ``` ```bash npx kordoc fill form.hwpx --dry-run # list fields only ``` ```bash npx kordoc watch ./incoming -d ./output # watch mode ``` ```bash npx kordoc watch ./docs --webhook https://api/hook # webhook notification ``` -------------------------------- ### Compare Two Documents Source: https://github.com/chrisryugj/kordoc/blob/main/README-EN.md Compare two document buffers to get statistics on added, removed, modified, and unchanged content. Supports comparing HWP against HWPX of the same document. ```typescript import { compare } from "kordoc" const diff = await compare(bufferA, bufferB) // diff.stats → { added: 3, removed: 1, modified: 5, unchanged: 42 } // diff.diffs → BlockDiff[] with cell-level table diffs ``` -------------------------------- ### MCP Server Configuration Source: https://github.com/chrisryugj/kordoc/blob/main/README-EN.md Configuration for an MCP server, specifying the command and arguments to run Kordoc. ```json { "mcpServers": { "kordoc": { "command": "npx", "args": ["-y", "kordoc", "mcp"] } } } ``` -------------------------------- ### 표준 들여쓰기 및 띄어쓰기 규칙 Source: https://github.com/chrisryugj/kordoc/blob/main/docs/gongmunseo-reference.md 공문서 항목별 표준 들여쓰기 및 항목 기호와 내용 사이의 띄어쓰기 규칙을 나타냅니다. 각 단계별 누적 들여쓰기(반각 공백 기준)와 예시를 포함합니다. ```text 1.∨○○○○○○ ∨∨가.∨○○○○○○ ∨∨∨∨1)∨○○○○○○ ∨∨∨∨∨∨가)∨○○○○○○ ∨∨∨∨∨∨∨∨(1)∨○○○○○○ ∨∨∨∨∨∨∨∨∨∨(가)∨○○○○○○ 2.∨○○○○○○ ``` -------------------------------- ### Generate HWPX from Markdown Source: https://github.com/chrisryugj/kordoc/blob/main/README-EN.md Convert Markdown text into an HWPX buffer. The generated HWPX can then be written to a file. ```typescript import { markdownToHwpx } from "kordoc" const hwpxBuffer = await markdownToHwpx("# Title\n\nParagraph text\n\n| A | B |\n| --- | --- |\n| 1 | 2 |") writeFileSync("output.hwpx", Buffer.from(hwpxBuffer)) ``` -------------------------------- ### Auto-Fill Forms in HWPX Source: https://github.com/chrisryugj/kordoc/blob/main/README-EN.md Fill form fields in an HWPX document while preserving original formatting. Requires reading the template file into a buffer and writing the result to a new file. ```typescript import { fillForm } from "kordoc" import { readFileSync, writeFileSync } from "fs" const template = readFileSync("application.hwpx") // HWPX style-preserving mode — keeps 100% of original formatting const result = await fillForm(template.buffer, { 성명: "홍길동", 주민등록번호: "900101-1234567", 주소: "서울특별시 광진구 능동로 120", }, { format: "hwpx-preserve" }) writeFileSync("filled.hwpx", Buffer.from(result.buffer!)) // result.filled → [{ label: "성명", value: "홍길동" }, ...] // result.unmatched → keys that didn't match any field ``` -------------------------------- ### 8단계 항목 부호 체계 구현 Source: https://github.com/chrisryugj/kordoc/blob/main/docs/gongmunseo-reference.md 공문서 항목 표시에 사용되는 8단계 부호 체계를 구현할 때, 5단계와 6단계는 반드시 괄호 3글자 조합으로, 7단계와 8단계는 단일 유니코드 문자로 출력해야 합니다. ```text 1. 첫째 가. 둘째 1) 셋째 가) 넷째 (1) 다섯째 (가) 여섯째 ① 일곱째 ㉮ 여덟째 ``` -------------------------------- ### Parse HWPX Document Source: https://github.com/chrisryugj/kordoc/blob/main/README-EN.md Parse an HWPX document buffer and access its markdown text, structured data, and metadata. Requires reading the file into a buffer. ```typescript import { parse } from "kordoc" import { readFileSync } from "fs" const buffer = readFileSync("document.hwpx") const result = await parse(buffer.buffer) if (result.success) { console.log(result.markdown) // Markdown text console.log(result.blocks) // IRBlock[] structured data console.log(result.metadata) // { title, author, createdAt, ... } } ``` -------------------------------- ### Core Parsing Functions Source: https://github.com/chrisryugj/kordoc/blob/main/README-EN.md These functions provide the core capabilities for parsing different document formats into Markdown with metadata. They handle auto-detection or specific format parsing. ```APIDOC ## Core API Functions ### `parse(buffer, options?)` #### Description Auto-detects the document format and parses it into Markdown with IRBlock[]. ### `parseHwpx(buffer, options?)` #### Description Parses HWPX documents specifically. ### `parseHwp(buffer, options?)` #### Description Parses HWP 5.x documents specifically. ### `parseHwp3(buffer, options?)` #### Description Parses HWP 3.x (1996–2002 legacy) documents specifically. ### `parsePdf(buffer, options?)` #### Description Parses PDF documents specifically. ### `parseXlsx(buffer, options?)` #### Description Parses XLSX documents specifically. ### `parseXls(buffer, options?)` #### Description Parses XLS (Excel 97–2003, BIFF8) documents specifically. ### `parseDocx(buffer, options?)` #### Description Parses DOCX documents specifically. ### `parseHwpml(buffer, options?)` #### Description Parses HWPML (XML-based HWP) documents specifically. ### `detectFormat(buffer)` #### Description Detects the file format and returns its type (e.g., "hwpx", "pdf", "docx", "unknown"). ``` -------------------------------- ### 9단계 이후 항목 부호 확장 규칙 Source: https://github.com/chrisryugj/kordoc/blob/main/docs/gongmunseo-reference.md 기본 8단계 항목 부호 체계 소진 시, 단모음 순서로 확장하는 규칙을 설명합니다. 이는 행정안전부 2020 편람에 수록된 내용입니다. ```text 가→나→다→…→파→하 → 거→너→더→…→퍼→허 → 고→노→도→… ``` -------------------------------- ### OCR for Image-Based PDFs Source: https://github.com/chrisryugj/kordoc/blob/main/README-EN.md Perform Optical Character Recognition (OCR) on image-based PDFs by providing an asynchronous OCR service function to the parse options. This function will be called for each page image. ```typescript const result = await parse(buffer, { ocr: async (pageImage, pageNumber, mimeType) => { return await myOcrService.recognize(pageImage) // Tesseract, Claude Vision, etc. } }) ``` -------------------------------- ### Parse Specific Pages of a Document Source: https://github.com/chrisryugj/kordoc/blob/main/README-EN.md Parse only specific pages of a document by providing a page range string or an array of page numbers to the parse function. ```typescript const result = await parse(buffer, { pages: "1-3" }) // pages 1-3 only const result = await parse(buffer, { pages: [1, 5, 10] }) // specific pages ``` -------------------------------- ### Advanced Functions Source: https://github.com/chrisryugj/kordoc/blob/main/README-EN.md These advanced functions offer more specialized document manipulation capabilities, including document comparison, form handling, and format conversions. ```APIDOC ## Advanced API Functions ### `compare(bufferA, bufferB, options?)` #### Description Performs a document diff at the IR (Intermediate Representation) level. ### `extractFormFields(blocks)` #### Description Recognizes and extracts form fields from IRBlock[]. ### `fillForm(buffer, values, options?)` #### Description Fills a form template with provided values. Supports markdown, hwpx, and hwpx-preserve formats. ### `fillFormFields(blocks, values)` #### Description Replaces form field values within IRBlock[]. ### `fillHwpx(buffer, values)` #### Description Directly manipulates HWPX XML for style-preserving form filling. ### `markdownToHwpx(markdown, options?)` #### Description Converts Markdown content to HWPX format. Supports theme options. ### `markdownToPdf(markdown, options?)` #### Description Generates a PDF document from Markdown content using a print renderer. ### `blocksToPdf(blocks, options?)` #### Description Generates a PDF document from IRBlock[]. ### `renderHtml(blocks, options?)` #### Description Renders IRBlock[] into print-ready HTML. ### `blocksToMarkdown(blocks)` #### Description Converts IRBlock[] into a Markdown string. ``` -------------------------------- ### Kordoc TypeScript Types Source: https://github.com/chrisryugj/kordoc/blob/main/README-EN.md Imports type definitions for various Kordoc functionalities, including parsing results, document structures, metadata, options, and conversion utilities. ```typescript import type { ParseResult, ParseSuccess, ParseFailure, FileType, PageQuality, DocumentQualitySummary, IRBlock, IRBlockType, IRTable, IRCell, CellContext, BoundingBox, InlineStyle, OutlineItem, ParseWarning, WarningCode, DocumentMetadata, ParseOptions, ErrorCode, DiffResult, BlockDiff, CellDiff, DiffChangeType, FormField, FormResult, FillResult, HwpxFillResult, FillOutputFormat, FillFormOutput, HwpxTheme, MarkdownToHwpxOptions, PrintPreset, PrintOptions, PageMargin, OcrProvider, WatchOptions, } from "kordoc" ``` -------------------------------- ### Extract Form Fields Source: https://github.com/chrisryugj/kordoc/blob/main/README-EN.md Extract form fields from parsed document blocks. Returns a list of fields with their labels, values, and positions, along with a confidence score. ```typescript import { parse, extractFormFields } from "kordoc" const result = await parse(buffer) if (result.success) { const form = extractFormFields(result.blocks) // form.fields → [{ label: "성명", value: "홍길동", row: 0, col: 0 }, ...] // form.confidence → 0.85 } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.