HWPJS를 사용하여 첫 번째 HWP 파일을 파싱해보세요.
먼저 패키지를 설치합니다.
npm install @ohah/hwpjs가장 간단한 사용 예제입니다.
// buffer-polyfill을 먼저 import한 후
import './buffer-polyfill';
import * as hwpjs from '@ohah/hwpjs';
// 파일 입력에서 HWP 파일 읽기
const fileInput = document.querySelector('input[type="file"]');
fileInput.addEventListener('change', async (e) => {
const file = (e.target as HTMLInputElement).files?.[0];
if (!file) return;
try {
const arrayBuffer = await file.arrayBuffer();
const data = new Uint8Array(arrayBuffer);
// JSON으로 변환
const jsonResult = hwpjs.toJson(data);
console.log(jsonResult);
} catch (error) {
console.error('변환 실패:', error);
}
});더 자세한 예제는 예제 페이지를 참고하세요.
명령줄에서 직접 사용하려면 CLI 가이드를 참고하세요.
# 전역 설치
npm install -g @ohah/hwpjs
# 사용 예제
hwpjs to-json document.hwp -o output.json
hwpjs to-markdown document.hwp -o output.md
hwpjs to-html document.hwp -o output.html