#빠른 시작
HWPJS를 사용하여 첫 번째 HWP 파일을 파싱해보세요.
#설치
먼저 패키지를 설치합니다.
npm
yarn
pnpm
bun
deno
npm install @ohah/hwpjsyarn add @ohah/hwpjspnpm add @ohah/hwpjsbun add @ohah/hwpjsdeno add npm:@ohah/hwpjs#예제
가장 간단한 사용 예제입니다.
Web
React Native
Node.js
// 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);
}
});import { Hwpjs } from '@ohah/hwpjs';
import RNFS from 'react-native-fs';
import { Platform } from 'react-native';
try {
// 파일 경로 설정
const filePath = Platform.OS === 'ios'
? `${RNFS.MainBundlePath}/document.hwp`
: `${RNFS.DocumentDirectoryPath}/document.hwp`;
// 파일을 base64로 읽기
const fileData = await RNFS.readFile(filePath, 'base64');
// base64를 ArrayBuffer로 변환
const binaryString = atob(fileData);
const length = binaryString.length;
const bytes = new Uint8Array(length);
for (let i = 0; i < length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
// HWP 파일 파싱 (ArrayBuffer 직접 사용)
const result = Hwpjs.toJson(bytes.buffer);
console.log('변환 성공:', result);
} catch (error) {
console.error('변환 실패:', error);
}import { readFileSync } from 'fs';
import { toJson } from '@ohah/hwpjs';
try {
// HWP 파일을 읽어서 JSON으로 변환
const fileBuffer = readFileSync('./document.hwp');
const data = new Uint8Array(fileBuffer);
const result = toJson(data);
console.log('변환 성공:', result);
} catch (error) {
console.error('변환 실패:', error);
}더 자세한 예제는 예제 페이지를 참고하세요.
#CLI 사용
명령줄에서 직접 사용하려면 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