📖 읽기
파일, URL, 바이트 배열에서 HWPX 문서 로드
Read from file, URL, or byte array
HWPX 파일 포맷 리더 & 라이터 — TypeScript
HWPX file format reader & writer — TypeScript
HWPX (한컴오피스 한글 문서) 파일을 읽고, 쓰고, 조작할 수 있는 TypeScript 라이브러리입니다.
A TypeScript library for reading, writing, and manipulating HWPX (Hancom Word) documents.
파일, URL, 바이트 배열에서 HWPX 문서 로드
Read from file, URL, or byte array
파일, 스트림, 바이트 배열로 문서 저장
Write to file, stream, or byte array
문단, 표, 그림, 필드 등 문서 요소 편집
Edit paragraphs, tables, images, fields
npm을 통해 간단히 설치할 수 있습니다.
Install via npm.
npm install ownhwpx
Node.js 18 이상이 필요합니다.
Requires Node.js 18 or later.
HWPX 문서를 읽고 텍스트를 추출하는 기본 예제입니다.
Basic example: read a HWPX document and extract text.
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`)
}
import { HWPXWriter, BlankFileMaker } from 'ownhwpx'
// 빈 문서 생성
const blank = BlankFileMaker.make()
await HWPXWriter.toFilepath(blank, 'blank.hwpx')
// 수정된 문서 저장
await HWPXWriter.toFilepath(doc, 'output.hwpx')
import { TextExtractor, TextExtractMethod } from 'ownhwpx'
const text = TextExtractor.extract(
doc,
TextExtractMethod.AppendControlTextAfterParagraphText,
true,
null
)
console.log(text)
ownhwpx가 제공하는 주요 클래스와 메서드입니다.
Key classes and methods provided by ownhwpx.
HWPX 문서 읽기 · Read HWPX documents
fromFilepath(path, nsAware?)fromFile(file, nsAware?)fromUrl(url, nsAware?)fromBytes(bytes, nsAware?)HWPX 문서 쓰기 · Write HWPX documents
toFilepath(hwpxFile, path)toBytes(hwpxFile)toStream(hwpxFile, stream)빈 문서 생성 · Create blank documents
make() → HWPXFile텍스트 추출 · Extract text content
extract(hwpxFile, method, ...)extractFrom(from, method, ...)extractFromRange(from, method, ..., start?, end?)템플릿 렌더링 · Template rendering
render(hwpxFile, context)renderToString(template, context)2차원 배열로 표 생성 · Table from array
make(data[][], options?)makeWithFormat(data[][], options?)목차 생성 · Table of contents
generate(hwpxFile, options?)insertToc(hwpxFile, options?)객체 검색 · Search objects
find(from, filter, firstOnly)필드 검색 · Find fields
find(from, fieldName, firstOnly)가로선 삽입 · Horizontal rule
insertAfter(para, options?)insertToRun(run, options?)구역 나누기 · Section break
append(hwpx, options?)insertAt(hwpx, index, options?)날짜 포맷팅 · Date formatting
format(format)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'로 치환됨
import { TableFromArray } from 'ownhwpx'
const table = TableFromArray.make([
['Name', 'Age', 'City'],
['Alice', '30', 'Seoul'],
['Bob', '25', 'Busan'],
], { headerRows: 1 })
// 문단에 표 추가
para.addNewRun().addItem(table)
import { TocMaker } from 'ownhwpx'
const entries = TocMaker.generate(doc)
console.log(entries)
TocMaker.insertToc(doc, {
tocTitle: 'Table of Contents',
maxLevel: 3,
})
import { ObjectFinder, ObjectType } from 'ownhwpx'
const results = ObjectFinder.find(doc, {
isMatched: obj => obj.objectType() === ObjectType.hp_fieldBegin
}, false)
import { FieldFinder } from 'ownhwpx'
const results = FieldFinder.find(doc, 'CustomerName', false)
for (const r of results) {
console.log(r.beginField?.name, r.endField?.beginIDRef)
}
import { HrMaker, LineWidth, LineType2 } from 'ownhwpx'
HrMaker.insertAfter(para, {
thickness: LineWidth.MM_0_4,
color: '#CCCCCC',
})
import { SectionBreakMaker } from 'ownhwpx'
// 새 구역 추가 (가로 레이아웃)
SectionBreakMaker.append(doc, { landscape: true })
// 특정 위치에 구역 삽입
SectionBreakMaker.insertAt(doc, 1, { marginTop: 3000 })
sample01.hwpx를 템플릿으로 불러와 JSON 데이터로 {{variable}}를 치환합니다.
Loads sample01.hwpx as a template and renders {{variable}} placeholders with your JSON data.
✅ 템플릿은 {{variable}} 텍스트 치환 방식과 누름틀(CLICK_HERE) 필드 방식을 모두 지원합니다.
✅ The template supports both {{variable}} text substitution and CLICK_HERE field (누름틀) approaches.
{{variable}} 치환 + {{#each}} 표 행 자동 생성 + 누름틀(CLICK_HERE)
템플릿 + 표/결제/서명에 들어갈 JSON
Click "Generate HWPX Document" to generate a rich document preview.
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, supports {{variable}} text substitution and CLICK_HERE (누름틀) fields
Returns rendered text + downloadable .hwpx file (Base64).
템플릿 없이 제목 단계(Heading Level) 데이터로 목차가 포함된 문서를 생성합니다.
Generates a HWPX document with a table of contents without a template — headings and hierarchy only.
JSON with title (string) and entries (array of {text, level})
Click "Generate TOC HWPX" to generate a document with table of contents.
POST /api/generate-toc
Content-Type: application/json
{
"title": "프로젝트 계획서",
"entries": [
{ "text": "개요", "level": 1 },
{ "text": "배경", "level": 2 },
{ "text": "목표", "level": 2 },
{ "text": "세부 계획", "level": 1 },
{ "text": "일정", "level": 2 },
{ "text": "개발 단계", "level": 3 },
{ "text": "테스트 단계", "level": 3 },
{ "text": "예산", "level": 2 },
{ "text": "결론", "level": 1 }
]
}
→ 200
{
"text": "...",
"hwpxBase64": "UEsDBBQAAAAIA...",
"size": 12345
}
powered by ownhwpx + Cloudflare Workers — uses TABLE_OF_CONTENTS field with 개요 1/2/3 outline styles. Open in HWP and press Update Field for correct page numbers.
템플릿 없이 배열 데이터로 직접 표를 생성합니다.
Generates a table HWPX document without a template — headers and rows only.
JSON with headers (array) and rows (array of arrays)
Click "Generate Table HWPX" to generate a table document from array data.
POST /api/generate-table
Content-Type: application/json
{
"headers": ["Name", "Age", "City"],
"rows": [
["Alice", "30", "Seoul"],
["Bob", "25", "Busan"],
["Charlie", "35", "Incheon"]
]
}
→ 200
{
"text": "...",
"hwpxBase64": "UEsDBBQAAAAIA...",
"size": 12345
}
powered by ownhwpx + Cloudflare Workers — no template file needed, pure code-based generation.