ownhwpx

HWPX 파일 포맷 리더 & 라이터 — TypeScript

HWPX file format reader & writer — TypeScript

HWPX (한컴오피스 한글 문서) 파일을 읽고, 쓰고, 조작할 수 있는 TypeScript 라이브러리입니다.
A TypeScript library for reading, writing, and manipulating HWPX (Hancom Word) documents.

npm Apache-2.0 Node ≥ 18 TypeScript

📖 읽기

파일, URL, 바이트 배열에서 HWPX 문서 로드

Read from file, URL, or byte array

✏️ 쓰기

파일, 스트림, 바이트 배열로 문서 저장

Write to file, stream, or byte array

🔄 조작

문단, 표, 그림, 필드 등 문서 요소 편집

Edit paragraphs, tables, images, fields

📦 설치 Installation


npm을 통해 간단히 설치할 수 있습니다.

Install via npm.

npm install ownhwpx

Node.js 18 이상이 필요합니다.

Requires Node.js 18 or later.

🚀 빠른 시작 Quick Start


HWPX 문서를 읽고 텍스트를 추출하는 기본 예제입니다.

Basic example: read a HWPX document and extract text.

문서 읽기 · Read a Document

import { HWPXReader } from 'ownhwpx'

const doc = HWPXReader.fromFilepath('document.hwpx')
console.log(`Sections: ${doc.sectionXMLFileList.length}`)

const section = doc.sectionXMLFileList.get(0)
for (let i = 0; i < section.paraListCore.count; i++) {
  const para = section.paraListCore.getPara(i)
  console.log(`Paragraph ${i}: ${para.runList.length} runs`)
}

문서 쓰기 · Write a Document

import { HWPXWriter, BlankFileMaker } from 'ownhwpx'

// 빈 문서 생성
const blank = BlankFileMaker.make()
await HWPXWriter.toFilepath(blank, 'blank.hwpx')

// 수정된 문서 저장
await HWPXWriter.toFilepath(doc, 'output.hwpx')

텍스트 추출 · Extract Text

import { TextExtractor, TextExtractMethod } from 'ownhwpx'

const text = TextExtractor.extract(
  doc,
  TextExtractMethod.AppendControlTextAfterParagraphText,
  true,
  null
)
console.log(text)

📚 API 문서 API Reference


ownhwpx가 제공하는 주요 클래스와 메서드입니다.

Key classes and methods provided by ownhwpx.

HWPXReader

HWPX 문서 읽기 · Read HWPX documents

  • fromFilepath(path, nsAware?)
  • fromFile(file, nsAware?)
  • fromUrl(url, nsAware?)
  • fromBytes(bytes, nsAware?)

HWPXWriter

HWPX 문서 쓰기 · Write HWPX documents

  • toFilepath(hwpxFile, path)
  • toBytes(hwpxFile)
  • toStream(hwpxFile, stream)

BlankFileMaker

빈 문서 생성 · Create blank documents

  • make()HWPXFile

TextExtractor

텍스트 추출 · Extract text content

  • extract(hwpxFile, method, ...)
  • extractFrom(from, method, ...)
  • extractFromRange(from, method, ..., start?, end?)

TemplateEngine

템플릿 렌더링 · Template rendering

  • render(hwpxFile, context)
  • renderToString(template, context)

TableFromArray

2차원 배열로 표 생성 · Table from array

  • make(data[][], options?)
  • makeWithFormat(data[][], options?)

TocMaker

목차 생성 · Table of contents

  • generate(hwpxFile, options?)
  • insertToc(hwpxFile, options?)

ObjectFinder

객체 검색 · Search objects

  • find(from, filter, firstOnly)

FieldFinder

필드 검색 · Find fields

  • find(from, fieldName, firstOnly)

HrMaker

가로선 삽입 · Horizontal rule

  • insertAfter(para, options?)
  • insertToRun(run, options?)

SectionBreakMaker

구역 나누기 · Section break

  • append(hwpx, options?)
  • insertAt(hwpx, index, options?)

DateHelper

날짜 포맷팅 · Date formatting

  • format(format)

💡 사용 예제 Usage Examples


템플릿 · Templates

import { TemplateEngine, BlankFileMaker } from 'ownhwpx'

const blank = BlankFileMaker.make()
const section = blank.sectionXMLFileList.get(0)
const para = section.paraListCore.getPara(0)

para.addNewRun().addNewT().addText('Hello, {{name}}!')

TemplateEngine.render(blank, { name: 'World' })
// 문서의 {{name}}이 'World'로 치환됨

표 생성 · Tables

import { TableFromArray } from 'ownhwpx'

const table = TableFromArray.make([
  ['Name', 'Age', 'City'],
  ['Alice', '30', 'Seoul'],
  ['Bob', '25', 'Busan'],
], { headerRows: 1 })

// 문단에 표 추가
para.addNewRun().addItem(table)

목차 · Table of Contents

import { TocMaker } from 'ownhwpx'

const entries = TocMaker.generate(doc)
console.log(entries)

TocMaker.insertToc(doc, {
  tocTitle: 'Table of Contents',
  maxLevel: 3,
})

객체 검색 · Object Search

import { ObjectFinder, ObjectType } from 'ownhwpx'

const results = ObjectFinder.find(doc, {
  isMatched: obj => obj.objectType() === ObjectType.hp_fieldBegin
}, false)

필드 검색 · Field Search

import { FieldFinder } from 'ownhwpx'

const results = FieldFinder.find(doc, 'CustomerName', false)
for (const r of results) {
  console.log(r.beginField?.name, r.endField?.beginIDRef)
}

가로선 · Horizontal Rule

import { HrMaker, LineWidth, LineType2 } from 'ownhwpx'

HrMaker.insertAfter(para, {
  thickness: LineWidth.MM_0_4,
  color: '#CCCCCC',
})

구역 나누기 · Section Break

import { SectionBreakMaker } from 'ownhwpx'

// 새 구역 추가 (가로 레이아웃)
SectionBreakMaker.append(doc, { landscape: true })

// 특정 위치에 구역 삽입
SectionBreakMaker.insertAt(doc, 1, { marginTop: 3000 })

🎮 라이브 문서 생성 · Live Document Generator


sample01.hwpx를 템플릿으로 불러와 JSON 데이터로 {{variable}}를 치환합니다.
Loads sample01.hwpx as a template and renders {{variable}} placeholders with your JSON data.

템플릿 · Template

{{variable}} 치환 + 표가 자동 생성됩니다

데이터 · Data (JSON)

템플릿 + 표/결제/서명에 들어갈 JSON

문서 미리보기 · Document Preview

Click "Generate HWPX Document" to generate a rich document preview.

API 명세 · API Reference
POST /api/render-hwpx
Content-Type: application/json

{
  "template": "본문 내용 {{variable}}...",
  "data": {
    "contractDate": "2026-07-11",
    "clientName": "홍길동",
    "items": [
      { "name": "디자인", "qty": 1, "price": 500000 }
    ],
    "amount": "500,000",
    "signature": "홍길동"
  }
}

→ 200
{
  "text": "...",
  "hwpxBase64": "UEsDBBQAAAAIA...",
  "size": 12345
}

powered by ownhwpx + Cloudflare Workers — loads sample01.hwpx, renders {{variable}} with TemplateEngine
Returns rendered text + downloadable .hwpx file (Base64).