快速开始

快速开始

这个页面介绍了阅读 OneNote 的最小步骤. .one 文件和 使用 Aspose.Note FOSS 进行Python 的输出到 PDF 中.


Prerequisites

RequirementDetail
Python3.10 or later
Packageaspose-note >= 26.3.2
OSWindows,macOS或Linux的版本
微软办公室不需要

第1步 安装

pip install aspose-note>=26.3.2

步骤2 加载一个OneNote文件

Document 是根入口点. 通过一个 .one 文件路径将加载:

from aspose.note import Document

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

步骤3 阅读页面和文本

GetChildNodes() 返回给定类型的所有直接后代. 在 Document 对于页面,以及每一张 Page 对于富文本的页面节点:

from aspose.note import Document, Page, RichText

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

步骤4 导出到PDF

Document.Save() 含有: SaveFormat.Pdf 没有任何外部染器的PDF生成:

from aspose.note import Document, SaveFormat

doc = Document("notebook.one")
doc.Save("output.pdf", SaveFormat.Pdf)

下一步步骤

See Also

 中文