LibreOfficeFileConverter

LibreOfficeFileConverter

LibreOffice의 커맨드라인 인터페이스(soffice)를 사용해 오피스 파일을 형식 간에 변환해주는 컴포넌트예요. 원본 파일을 다운스트림 컨버터가 지원하는 형식으로 바꿔야 할 때, 문서 컨버터(예: DOCXToDocument) 앞에 두면 돼요.

출처: LibreOfficeFileConverter

본문

개요

LibreOfficeFileConverter는 LibreOffice의 soffice 커맨드라인 유틸리티로 오피스 파일을 한 형식에서 다른 형식으로 변환해요. 문서·스프레드시트·프레젠테이션 형식을 폭넓게 지원해서, 파이프라인이 다운스트림 컨버터가 지원하지 않는 형식의 파일을 받을 때 유용해요.

대부분의 컨버터와 달리 LibreOfficeFileConverter는 Haystack Document가 아니라 ByteStream 객체를 출력해요. 그래서 보통 문서 컨버터(예: DOCXToDocument나 PyPDFToDocument)와 연결해 최종 Document를 만들어요.

LibreOffice가 설치돼 있어야 하고 soffice로 PATH에 있어야 해요. 자세한 내용은 LibreOffice 설치 가이드를 참고하세요.

지원되는 변환

카테고리 입력 형식 가능한 출력 형식
문서 doc, docx, odt, rtf, txt, html pdf, docx, doc, odt, rtf, txt, html, epub
스프레드시트 xlsx, xls, ods, csv pdf, xlsx, xls, ods, csv, html
프레젠테이션 pptx, ppt, odp pdf, pptx, ppt, odp, html, png, jpg

이 목록은 전부가 아니에요. 모든 지원 변환은 LibreOffice 필터 문서를 확인하세요.

사용법

LibreOffice 통합을 설치해요.

pip install libreoffice-haystack

단독 사용:

from pathlib import Path
from haystack_integrations.components.converters.libreoffice import (
    LibreOfficeFileConverter,
)

converter = LibreOfficeFileConverter()
result = converter.run(sources=[Path("sample.doc")], output_file_type="docx")
bytestreams = result["output"]

매번 run() 호출 때 넘기기 싫으면 초기화 시점에 output_file_type을 설정할 수도 있어요.

converter = LibreOfficeFileConverter(output_file_type="pdf")
result = converter.run(sources=[Path("report.pptx")])

파이프라인 안에서:

LibreOfficeFileConverter를 문서 컨버터와 연결하는 게 흔한 패턴이에요. 아래 예시는 예전 .doc 파일을 .docx로 변환한 뒤 Haystack Document로 추출해요.

from pathlib import Path
from haystack import Pipeline
from haystack.components.converters import DOCXToDocument
from haystack_integrations.components.converters.libreoffice import (
    LibreOfficeFileConverter,
)

pipeline = Pipeline()
pipeline.add_component(
    "libreoffice_converter",
    LibreOfficeFileConverter(output_file_type="docx"),
)
pipeline.add_component("docx_converter", DOCXToDocument())

pipeline.connect("libreoffice_converter.output", "docx_converter.sources")

result = pipeline.run(
    {"libreoffice_converter": {"sources": [Path("legacy_report.doc")]}},
)
documents = result["docx_converter"]["documents"]

더 알아보기 (Learn more)