TypeScript library for reading and writing Korean HWP/HWPX documents.
한글(HWP/HWPX) 문서를 읽고 쓰는 TypeScript 라이브러리.
📖 Read HWPX files — tested on 349 real-world documents
✍️ Write HWPX files — programmatic document creation with builder API
📄 Read HWP 5.x binary files (OLE2/CFB format)
🔄 Round-trip preservation — parse → write → identical output
📊 Rich content extraction — tables, images, equations, shapes, headers/footers, footnotes
📐 Page layout — size, margins, columns, section properties
🔤 Full text extraction with per-section support
🔁 Format conversion — DOCX ↔ HWPX, HTML export, PDF export
👁️ Web viewer — React component for rendering HWPX documents
✏️ Web editor — ProseMirror-based WYSIWYG editor (in progress)
npm install @handoc/hwpx-parser @handoc/hwpx-writer
import { HanDoc } from '@handoc/hwpx-parser' ;
import fs from 'fs' ;
const doc = await HanDoc . open ( new Uint8Array ( fs . readFileSync ( 'document.hwpx' ) ) ) ;
// Extract all text
console . log ( doc . extractText ( ) ) ;
// Access structured data
for ( const section of doc . sections ) {
console . log ( section ) ;
}
// Images, tables, metadata
console . log ( doc . metadata ) ; // { title, creator, language }
console . log ( doc . images ) ; // [{ path, data, contentType }, ...]
import { readHwp , extractTextFromHwp } from '@handoc/hwp-reader' ;
import fs from 'fs' ;
const buf = new Uint8Array ( fs . readFileSync ( 'document.hwp' ) ) ;
const text = extractTextFromHwp ( buf ) ;
console . log ( text ) ;
Create an HWPX from scratch
import { HwpxBuilder } from '@handoc/hwpx-writer' ;
import fs from 'fs' ;
const bytes = HwpxBuilder . create ( )
. addParagraph ( 'Hello World' , { bold : true , fontSize : 20 } )
. addTable ( [ [ 'Name' , 'Score' ] , [ 'Alice' , '95' ] ] )
. addParagraph ( 'Second paragraph' )
. build ( ) ;
fs . writeFileSync ( 'output.hwpx' , bytes ) ;
import { HanDoc } from '@handoc/hwpx-parser' ;
import { writeDOCX } from '@handoc/docx-writer' ;
import fs from 'fs' ;
const doc = await HanDoc . open ( new Uint8Array ( fs . readFileSync ( 'input.hwpx' ) ) ) ;
const docxBuffer = await writeDOCX ( doc ) ;
fs . writeFileSync ( 'output.docx' , docxBuffer ) ;
This is a monorepo with 12 packages:
Package
Description
Version
@handoc/viewer
React component for rendering HWPX documents in the browser
0.1.0
@handoc/editor
ProseMirror-based HWPX document editor
0.1.0
Package
Description
Version
@handoc/cli
CLI tool for HanDoc - inspect, extract, and convert HWP/HWPX documents
0.1.0
Level 1: HWPX Read/Write + HWP 5.x Read ✅ Complete
Level 2: Format Conversion ✅ Complete
Level 3: PDF Export ✅ Complete
Level 4: Web Viewer ✅ Complete
Level 5: Web Editor 🟡 In Progress
@handoc/hwpx-parser — HanDoc
API
Description
HanDoc.open(buf)
Parse an HWPX buffer, returns Promise<HanDoc>
doc.extractText()
Get all text as a single string
doc.extractTextBySection()
Get text per section as string[]
doc.sections
Parsed section tree (paragraphs, tables, shapes, etc.)
doc.header
Document header (fonts, styles, char/para properties)
doc.metadata
{ title, creator, language }
doc.images
Embedded images with binary data
doc.sectionProps
Page size, margins, columns
doc.headers / doc.footers
Page headers and footers
doc.footnotes
Footnotes
doc.warnings
Parse warnings (non-fatal issues)
API
Description
writeHwpx(doc, original?)
Serialize a document model to HWPX bytes
HwpxBuilder.create()
Fluent builder for creating documents from scratch
.addParagraph(text, style?)
Add text with optional { bold, italic, fontSize, align }
.addTable(rows)
Add a table from a 2D string array
.addImage(data, ext, w?, h?)
Add an image
.addSectionBreak()
Start a new section
.build()
Returns Uint8Array of the HWPX file
API
Description
readHwp(buf)
Parse HWP 5.x binary, returns HwpDocument
extractTextFromHwp(buf)
Extract plain text from HWP binary
openCfb(buf)
Low-level OLE2/CFB reader
parseRecords(stream)
Parse HWP binary records
Packages: 12 (monorepo with Turborepo + pnpm)
Source Code: 7,809 lines (TypeScript)
Tests: 469 passed
Real Documents: 570/570 parsed (349 HWPX + 221 HWP)
Build: 12/12 packages ✅
pnpm install
pnpm build # Build all packages
pnpm test # Run all tests
pnpm typecheck # Type check
Contributions are welcome! Please:
Fork the repository
Create a feature branch (git checkout -b feature/amazing-feature)
Commit your changes (git commit -m 'Add some amazing feature')
Push to the branch (git push origin feature/amazing-feature)
Open a Pull Request
MIT © MUIN Company
본 제품은 한글과컴퓨터의 HWP 문서 파일(.hwp) 공개 문서를 참고하여 개발하였습니다.