소개

Aspose.Note FOSS for Python (aspose-note on PyPI)는 Microsoft OneNote .one 파일을 읽고 순수 Python로 PDF로 내보내는 무료 MIT 라이선스 라이브러리입니다. 버전 26.3.2는 페이지, 개요, 리치 텍스트 노드, 이미지 및 첨부 파일을 포괄하는 완전한 문서 객체 모델을 제공하며, Microsoft Office 설치나 Windows 의존성이 필요하지 않습니다.


주요 기능

문서 로드 및 형식 감지

Document은(는) 객체 모델의 루트입니다. 파일 경로를 전달하여 지원되는 모든 OneNote 형식을 로드하십시오. FileFormat 속성은 감지된 형식을 보고합니다.

from aspose.note import Document, FileFormat

doc = Document("notebook.one")
print(f"Format : {doc.FileFormat}")
print(f"Pages  : {len(list(doc))}")

페이지 및 제목 탐색

페이지는 Document 바로 아래에 있는 Page 노드입니다. 각 Page는 Author, CreationTime, Title와 같은 메타데이터를 노출합니다. Title 노드는 차례로 TitleText, TitleDate, TitleTime를 RichText 자식으로 제공합니다.

from aspose.note import Document, Page

doc = Document("notebook.one")
for page in doc.GetChildNodes(Page):
    print(f"Author  : {page.Author}")
    print(f"Created : {page.CreationTime}")
    if page.Title and page.Title.TitleText:
        print(f"Title   : {page.Title.TitleText}")

리치 텍스트 콘텐츠 읽기

RichText 노드는 실제 텍스트 내용을 담고 있는 리프 노드입니다. 표준 for 루프를 사용하여 RichText 객체를 반복하십시오 — 각 항목은 문자열 세그먼트입니다. Append()을(를) 사용하여 스타일이 적용된 새 텍스트를 추가합니다.

from aspose.note import Document, Page, Outline, RichText

doc = Document("notebook.one")
for page in doc.GetChildNodes(Page):
    for rt in page.GetChildNodes(RichText):
        text = "".join(rt)
        if text.strip():
            print(text[:120])

레이아웃 속성 개요

Outline 노드는 레이아웃 좌표를 노출합니다: HorizontalOffset, VerticalOffset, MaxWidth, MaxHeight, 및 MinWidth. 이는 레이아웃을 인식한 추출이나 페이지 재구성에 유용합니다.

from aspose.note import Document, Outline

doc = Document("notebook.one")
for outline in doc.GetChildNodes(Outline):
    print(f"HOffset={outline.HorizontalOffset}  VOffset={outline.VerticalOffset}  MaxW={outline.MaxWidth}")

문서 트리 구축

새로 CompositeNode.AppendChildLast()을(를) 사용하여 Document을(를) 처음부터 구축합니다. 각 노드 유형은 유효한 상위 노드에 추가될 수 있습니다: Page → Document, Outline → Page, RichText 노드 → Outline.

from aspose.note import Document, Page, Outline, RichText, ParagraphStyle, Title, SaveFormat

doc = Document()
page = Page()

title_text = RichText()
title_text.Append("My New Page", ParagraphStyle())
title = Title()
title.TitleText = title_text
page.Title = title

outline = Outline()
page.AppendChildLast(outline)
doc.AppendChildLast(page)
doc.Save("new_notebook.pdf", SaveFormat.Pdf)

PDF로 내보내기

Document.Save()은(는) SaveFormat.Pdf을(를) 받아 PDF를 파일 경로에 쓰거나 BytesIO 버퍼에 기록합니다. 내보내기는 외부 렌더러 없이 완전히 프로세스 내에서 실행됩니다.

import io
from aspose.note import Document, SaveFormat

doc = Document("notebook.one")

# File output
doc.Save("export.pdf", SaveFormat.Pdf)

# In-memory buffer
buf = io.BytesIO()
doc.Save(buf, SaveFormat.Pdf)
print(f"PDF bytes: {len(buf.getvalue())}")

빠른 시작

pip install aspose-note-foss
from aspose.note import Document, Page, RichText, SaveFormat

doc = Document("notebook.one")

# Print all text
for page in doc.GetChildNodes(Page):
    for rt in page.GetChildNodes(RichText):
        print("".join(rt))

# Export to PDF
doc.Save("output.pdf", SaveFormat.Pdf)

지원되는 포맷

포맷확장자읽기쓰기
OneNote 2010.one✓—
OneNote 2007.one✓—
OneNote 온라인.one✓—
PDF.pdf—✓

오픈 소스 및 라이선스

Aspose.Note FOSS for Python은 MIT 라이선스 하에 배포됩니다. PyPI에서 aspose-note으로 설치하십시오. 상업적 사용, 재배포 및 수정이 모두 허용됩니다.


시작하기

관련 리소스