๋ฐ์ํ
๊ฐ์
- ๋ฆฌ๋ ์ค ํ๊ฒฝ์ ํ์ด์ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ์กด์ฌํ์ง ์์ (hwp to pdf)
- ํ๊ธ๊ณผ ์ปดํจํฐ ์ ๋ฃ API๋ฅผ ์ฌ์ฉํ๋ฉด ๊ฐ๋ฅํ ์ ์์ง๋ง, ์๋ฒ์ ํ์ปดํตํฉ๋ทฐ์ด๊ฐ ์ค์น ๋์ด์ผ ํจ.
- libreoffice ๋ผ๋ ์ฐ๋ถํฌ ํจํค์ง์ extention์ ํตํด ๋ณํ ๊ฐ๋ฅํ์ฌ ๋ฆฌ๋ ์ค ํ๊ฒฝ์ ๊ด๋ จ ํจํค์ง ์ค์น ํ CLI ๋ช ๋ น์ด๋ฅผ ์คํํ๋ ๋ฐฉ์์ผ๋ก ์งํ
์ค์น ๋ฐ ํ ์คํธ
1. libreoffice ์ค์น
sudo apt update && sudo apt install libreoffice -y
2. ํ๊ธ ํฐํธ ์ค์น
sudo apt install fonts-nanum fonts-noto-cjk fonts-unfonts-core
3. ํ๊ธ ์ง์ libreoffice extention ์ค์น
libreoffice --headless --norestore --nofirststartwizard --accept="socket,host=localhost,port=2002;urp;" --nodefault --nologo &
sleep 10
sudo unopkg add --shared /tmp/H2Orestart-0.7.0.oxt
pkill -f soffice
4. ์คํ ๋ช ๋ น์ด
libreoffice --headless --infilter=Hwp2002_File --convert-to pdf:writer_pdf_Export --outdir ./output sample.hwp
5. ์ ์ค์ ํ ํ์ด์ฌ ์คํ ์ฝ๋ ์์
import os
def convert_hwp_to_pdf(hwp_file, output_dir="../data/output"):
"""
HWP ํ์ผ์ PDF๋ก ๋ณํํ๋ ํจ์ (LibreOffice ์ฌ์ฉ)
:param hwp_file: ๋ณํํ HWP ํ์ผ ๊ฒฝ๋ก
:param output_dir: ๋ณํ๋ PDF ์ ์ฅ ๋๋ ํ ๋ฆฌ (๊ธฐ๋ณธ๊ฐ: ./output)
"""
# ์ถ๋ ฅ ๋๋ ํ ๋ฆฌ๊ฐ ์์ผ๋ฉด ์์ฑ
os.makedirs(output_dir, exist_ok=True)
# LibreOffice ๋ช
๋ น์ด ์คํ
os.system(f'libreoffice --headless --infilter=Hwp2002_File --convert-to pdf:writer_pdf_Export --outdir {output_dir} "{hwp_file}"')
# ์ฌ์ฉ ์์
hwp_file = "../data/sample.hwp"
convert_hwp_to_pdf(hwp_file)