Aspose.Note FOSS for Python Is Now Available

我们很高兴宣布已发布 Aspose.Note FOSS for Python 在 PyPI 上。这个免费、开源的库让 Python 开发者读取 Microsoft OneNote .one 章节文件,遍历其完整的文档对象模型,提取内容,并导出为 PDF,无需 Microsoft Office 或任何专有运行时。.

立即安装::

pip install aspose-note

用于 PDF 导出::

pip install "aspose-note[pdf]"

什么是 Aspose.Note FOSS for Python??

Aspose.Note FOSS for Python is a 100% free, MIT-licensed Python library that provides an Aspose.Note-shaped public API (aspose.note.*) 用于读取 Microsoft OneNote .one 文件。它由内置的纯-Python MS-ONE/OneStore 二进制解析器提供支持,无需 COM 互操作、平台本机 DLL,也不需要安装 Microsoft Office。.

API 接口模型参考 Aspose.Note for .NET, 使已经在其他平台使用 Aspose 产品的团队能够轻松迁移。.


关键功能

读取任意 .one 文件

从文件路径或任意二进制流加载 OneNote 2010、OneNote Online 和 OneNote 2007 节文件::

from aspose.note import Document

doc = Document("MyNotes.one")
print(doc.DisplayName)   # Section name
print(len(list(doc)))       # Number of pages

遍历完整的文档 DOM

该库提供了完整的文档对象模型:: Document → Page → Outline → OutlineElement → RichText / Image / Table / AttachedFile. 使用 GetChildNodes(Type) 用于递归、类型过滤的搜索::

from aspose.note import Document, RichText

doc = Document("MyNotes.one")
all_text = [rt.Text for rt in doc.GetChildNodes(RichText) if rt.Text]

提取带有丰富格式的文本

每个 RichText 节点包含一个列表 TextRun 段落。每个运行携带每个字符的 TextStyle 元数据:粗体、斜体、下划线、字体名称、字体颜色、超链接地址等::

from aspose.note import Document, RichText

doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
    for run in rt.TextRuns:
        if run.Style.IsHyperlink:
            print(f"  Link: {run.Text} -> {run.Style.HyperlinkAddress}")
        elif run.Style.IsBold:
            print(f"  Bold: {run.Text}")

保存图像和附件

检索嵌入的图像为原始字节,并获取文件名和尺寸。将附件文件保存到磁盘::

from aspose.note import Document, Image, AttachedFile

doc = Document("MyNotes.one")
for img in doc.GetChildNodes(Image):
    with open(img.FileName or "image.bin", "wb") as f:
        f.write(img.Bytes)

for af in doc.GetChildNodes(AttachedFile):
    with open(af.FileName or "attachment.bin", "wb") as f:
        f.write(af.Bytes)

解析表格

行走 Table → TableRow → TableCell 层次结构并读取单元格内容::

from aspose.note import Document, Table, TableRow, TableCell, RichText

doc = Document("MyNotes.one")
for table in doc.GetChildNodes(Table):
    for row in table.GetChildNodes(TableRow):
        cells = [
            " ".join(rt.Text for rt in cell.GetChildNodes(RichText))
            for cell in row.GetChildNodes(TableCell)
        ]
        print(cells)

导出为 PDF

使用可选的 ReportLab 后端将任何已加载的文档保存为 PDF。使用以下方式配置页面范围和标签图标渲染 PdfSaveOptions:

from aspose.note import Document, SaveFormat

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

支持的内容类型

内容支持的
页面及页面标题
纯文本(RichText.Text)
格式化文本块(粗体、斜体、下划线、字体、颜色)
文本块中的超链接
嵌入式图像(字节、文件名、尺寸)
附件文件(字节、文件名)
表格(行、单元格、列宽)
OneNote 标签(NoteTag:形状、标签、颜色)
编号和项目符号列表(NumberList)
页面元数据(作者、创建时间、层级)
PDF 导出是(需要 ReportLab)
写回至 .one不支持
加密文档不支持

为 .NET 开发者提供熟悉的 API

已经使用 Aspose 的团队。注意,对于 .NET,将会立即识别 Python API。核心类例如 Document, Page, RichText, Image, DocumentVisitor,,以及 SaveFormat 在名称和行为上匹配 .NET 的等价物。.

对于需要完整写入支持、转换为其他格式或加密文档处理的场景,商业版 Aspose.Note for .NETAspose.Note for Java 产品可供使用。.


安装概述

命令目的
pip install aspose-note核心库(读取、遍历、DOM 访问)
pip install "aspose-note[pdf]"核心 + PDF 导出(添加 ReportLab)
pip install -e ".[pdf]"可编辑的源码安装(贡献者)

要求::Python 3.10、3.11 或 3.12。无需 Microsoft Office。.


快速入门