#설치하기
HWPJS는 여러 플랫폼에서 사용할 수 있습니다. 사용할 환경에 맞는 설치 방법을 선택하세요.
#설치
npm
yarn
pnpm
bun
deno
npm install @ohah/hwpjsyarn add @ohah/hwpjspnpm add @ohah/hwpjsbun add @ohah/hwpjsdeno add npm:@ohah/hwpjs#플랫폼별 설정
#React Native
iOS와 Android 프로젝트는 자동으로 설정됩니다. 추가 설정이 필요하지 않습니다.
#CLI 설치
명령줄 인터페이스를 사용하려면 전역 설치가 필요합니다:
npm install -g @ohah/hwpjs또는 npx를 사용하여 전역 설치 없이 사용할 수 있습니다:
npx @ohah/hwpjs <command>더 자세한 내용은 CLI 가이드를 참고하세요.
#사용 예제
Web
React Native
Node.js
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('JSON 변환 성공:', jsonResult);
// 마크다운으로 변환
const markdownResult = hwpjs.toMarkdown(data, {
image: 'base64', // 또는 'blob'
useHtml: true,
includeVersion: true,
includePageInfo: false,
});
console.log('마크다운 변환 성공:', markdownResult.markdown);
} 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 {
const fileBuffer = readFileSync('./document.hwp');
const data = new Uint8Array(fileBuffer);
const result = toJson(data);
console.log('변환 성공:', result);
} catch (error) {
console.error('변환 실패:', error);
}더 자세한 예제는 예제 페이지를 참고하세요.
#개발 환경 설정
프로젝트를 개발하기 위한 환경 설정은 개발 환경 설정 문서를 참고하세요.