Features Overview — Aspose.Note FOSS for Python
Aspose.Note FOSS for Python (package aspose-note, version 26.3.2) provides a Python API for reading Microsoft OneNote .one section files and exporting them to PDF. All features listed below are verified against the repository source code, README, and example scripts.
Installation and Setup
Install from PyPI:
pip install aspose-noteFor PDF export support (requires ReportLab):
pip install "aspose-note[pdf]"Requirements: Python 3.10 or later. No Microsoft Office installation required.
Features and Capabilities
.one File Loading
Load Microsoft OneNote section files from a file path or any binary stream (file handle, io.BytesIO, HTTP response body, cloud storage stream).
Document.FileFormatprovides a best-effort indication of the OneNote file format version (OneNote2010, OneNoteOnline, or OneNote2007)- Stream-based loading eliminates disk I/O for in-memory or network workflows
LoadOptions.LoadHistoryflag controls whether page history is included in the DOM
from aspose.note import Document
##From a file path
doc = Document("notebook.one")
##From a binary stream
with open("notebook.one", "rb") as f:
doc = Document(f)Document DOM Traversal
The full OneNote document is exposed as a tree of typed Python objects. Every node inherits from Node or CompositeNode:
Document: root; exposesDisplayName,CreationTime,FileFormatPage: direct child ofDocument; exposesTitle,Author,CreationTime,LastModifiedTime,LevelTitle: exposesTitleText,TitleDate,TitleTime(allRichTextnodes)Outline: positional container withHorizontalOffset,VerticalOffset,MaxWidth,MaxHeight,MinWidth,ReservedWidth,IndentPositionOutlineElement: leaf container; exposesNumberList
Navigation methods on CompositeNode:
| Method / Property | Description |
|---|---|
FirstChild, LastChild | Direct child access |
GetChildNodes(Type) | Recursive, type-filtered search |
AppendChildLast(node) | Add child at end |
AppendChildFirst(node) | Add child at start |
InsertChild(index, node) | Insert at position |
RemoveChild(node) | Remove a child |
for child in node | Iterate direct children |
from aspose.note import Document, Page, Outline, OutlineElement, RichText
doc = Document("notebook.one")
for page in doc.GetChildNodes(Page):
title_text = page.Title.TitleText.Text if page.Title and page.Title.TitleText else ""
print(f"Page: {title_text}")
for outline in page.GetChildNodes(Outline):
for oe in outline.GetChildNodes(OutlineElement):
for rt in oe.GetChildNodes(RichText):
print(f" {rt.Text}")Rich Text Content Extraction
RichText nodes expose:
Text: str: full plain-text stringTextRuns: list[TextRun]: list of formatted segmentsTags: list[NoteTag]: OneNote tags attached to this blockAppend(text, style=None): append a text run in-memoryReplace(old_value, new_value): in-memory string substitution
Each TextRun carries:
| Property | Type | Description |
|---|---|---|
Text | str | Segment text |
Style | TextStyle | Formatting metadata |
TextStyle properties:
| Property | Type |
|---|---|
IsBold, IsItalic, IsUnderline, IsStrikethrough | bool |
IsSuperscript, IsSubscript | bool |
FontName | str | None |
FontSize | float | None |
FontColor, Highlight | int | None (ARGB) |
Language | int | None |
IsHyperlink | bool |
HyperlinkAddress | str | None |
from aspose.note import Document, RichText
doc = Document("notebook.one")
for rt in doc.GetChildNodes(RichText):
for run in rt.TextRuns:
if run.Style.IsHyperlink:
print(f"Hyperlink: {run.Text} -> {run.Style.HyperlinkAddress}")
if run.Style.IsBold:
print(f"Bold text: {run.Text}")Image Extraction
Image nodes expose raw bytes and metadata for every embedded image:
| Property | Type | Description |
|---|---|---|
FileName | str | None | Original filename |
Bytes | bytes | Raw image data |
Width, Height | float | None | Dimensions in points |
AlternativeTextTitle | str | None | Alt text title |
AlternativeTextDescription | str | None | Alt text description |
HyperlinkUrl | str | None | Linked URL |
Tags | list[NoteTag] | Attached OneNote tags |
from aspose.note import Document, Image
doc = Document("notebook.one")
for i, img in enumerate(doc.GetChildNodes(Image), start=1):
filename = img.FileName or f"image_{i}.bin"
with open(filename, "wb") as f:
f.write(img.Bytes)
print(f"Saved: {filename} ({img.Width} x {img.Height} pts)")Attached File Extraction
AttachedFile nodes expose embedded file attachments:
| Property | Type | Description |
|---|---|---|
FileName | str | None | Original filename |
Bytes | bytes | Raw file data |
Tags | list[NoteTag] | Attached OneNote tags |
from aspose.note import Document, AttachedFile
doc = Document("notebook.one")
for i, af in enumerate(doc.GetChildNodes(AttachedFile), start=1):
filename = af.FileName or f"attachment_{i}.bin"
with open(filename, "wb") as f:
f.write(af.Bytes)Table Parsing
Table, TableRow, and TableCell expose the full table structure:
| Class | Key Properties |
|---|---|
Table | Columns: list[TableColumn] (each TableColumn has .Width and .LockedWidth), IsBordersVisible: bool, Tags: list[NoteTag] |
TableRow | Iterate cells via GetChildNodes(TableCell) |
TableCell | Contains RichText, Image, and other content nodes |
from aspose.note import Document, Table, TableRow, TableCell, RichText
doc = Document("notebook.one")
for table in doc.GetChildNodes(Table):
print("Column widths:", [col.Width for col in table.Columns])
for r, row in enumerate(table.GetChildNodes(TableRow), start=1):
cells = row.GetChildNodes(TableCell)
values = [
" ".join(rt.Text for rt in cell.GetChildNodes(RichText)).strip()
for cell in cells
]
print(f"Row {r}:", values)OneNote Tag Inspection
NoteTag appears on RichText, Image, AttachedFile, and Table nodes via their .Tags property. OutlineElement does not have a .Tags property. NoteTag properties:
| Property | Type | Description |
|---|---|---|
Icon | int | None | Numeric tag icon identifier |
Label | str | None | Display label string |
FontColor | int | None | Text color as ARGB integer |
Highlight | int | None | Highlight color as ARGB integer |
CreationTime | datetime | None | Tag creation timestamp |
CompletedTime | datetime | None | Tag completion timestamp (None if not completed) |
Factory method: NoteTag.CreateYellowStar() creates a standard yellow-star tag node.
from aspose.note import Document, RichText
doc = Document("notebook.one")
for rt in doc.GetChildNodes(RichText):
for tag in rt.Tags:
print(f"Tag: {tag.Label} (icon={tag.Icon}, completed={tag.CompletedTime})")Numbered List Support
OutlineElement.NumberList exposes:
| Property | Type | Description |
|---|---|---|
Format | str | None | List number format string |
Restart | int | None | Start number (for restarted lists) |
from aspose.note import Document, OutlineElement
doc = Document("notebook.one")
for oe in doc.GetChildNodes(OutlineElement):
nl = oe.NumberList
if nl:
print(f"format={nl.Format!r}")DocumentVisitor Traversal
DocumentVisitor provides a visitor pattern for structured full-document traversal. Override any VisitXxxStart / VisitXxxEnd method to intercept specific node types:
VisitDocumentStart(doc)/VisitDocumentEnd(doc)VisitPageStart(page)/VisitPageEnd(page)VisitTitleStart(title)/VisitTitleEnd(title)VisitOutlineStart(outline)/VisitOutlineEnd(outline)VisitOutlineElementStart(oe)/VisitOutlineElementEnd(oe)VisitRichTextStart(rt)/VisitRichTextEnd(rt)VisitImageStart(img)/VisitImageEnd(img)
from aspose.note import Document, DocumentVisitor, Page, RichText, Image
class MySummaryVisitor(DocumentVisitor):
def __init__(self):
self.pages, self.texts, self.images = 0, 0, 0
def VisitPageStart(self, page: Page) -> None:
self.pages += 1
def VisitRichTextStart(self, rt: RichText) -> None:
self.texts += 1
def VisitImageStart(self, img: Image) -> None:
self.images += 1
doc = Document("notebook.one")
v = MySummaryVisitor()
doc.Accept(v)
print(f"Pages={v.pages} RichText={v.texts} Images={v.images}")PDF Export
Save a loaded document to PDF using Document.Save(). Supported via the optional ReportLab backend.
from aspose.note import Document, SaveFormat
doc = Document("notebook.one")
doc.Save("output.pdf", SaveFormat.Pdf)PdfSaveOptions
| Option | Type | Description |
|---|---|---|
PageIndex | int | Zero-based index of the first page to export (default: 0, first page) |
PageCount | int | None | Number of pages to export starting from PageIndex; None exports all remaining pages |
ImageCompression | Any | None | Image compression setting for the PDF output |
JpegQuality | int | None | JPEG quality (0–100) for compressed images in the PDF |
PageSettings | Any | None | Per-page size and orientation settings |
PageSplittingAlgorithm | Any | None | Algorithm used to split long content across PDF pages |
import io
from aspose.note import Document, SaveFormat
from aspose.note.saving import PdfSaveOptions
doc = Document("notebook.one")
##Save to file
doc.Save("output.pdf", SaveFormat.Pdf)
##Save to in-memory stream
buf = io.BytesIO()
doc.Save(buf, PdfSaveOptions())
pdf_bytes = buf.getvalue()Format and Enum Reference
SaveFormat
| Value | Status |
|---|---|
SaveFormat.Pdf | Implemented via ReportLab; raises ValueError if format handler not registered |
FileFormat
Document.FileFormat provides a best-effort indication of the OneNote file format version. The enum declares three values:
| Value | Description |
|---|---|
FileFormat.OneNote2010 | OneNote 2010 format |
FileFormat.OneNoteOnline | OneNote Online format |
FileFormat.OneNote2007 | OneNote 2007 format |
NodeType
NodeType.Document, NodeType.Page, NodeType.Outline, NodeType.OutlineElement, NodeType.RichText, NodeType.Image, NodeType.Table, NodeType.AttachedFile
HorizontalAlignment
HorizontalAlignment.Left, HorizontalAlignment.Center, HorizontalAlignment.Right
Current Limitations
| Limitation | Detail |
|---|---|
| Read-only | Writing back to .one format is not implemented |
| No encryption | Encrypted documents raise IncorrectPasswordException |
| PDF only for export | Other SaveFormat values raise UnsupportedSaveFormatException |
| ReportLab required for PDF | Install pip install "aspose-note[pdf]" separately |
GetPageHistory returns single-element list | Full page history traversal is a stub; returns [page] |
DetectLayoutChanges() | Compatibility stub; no operation |
Tips and Best Practices
- Check for None:
Page.Title,Title.TitleText,OutlineElement.NumberList, and most metadata fields can beNone. Always guard withif x is not Noneorif xbefore accessing properties. - Use
GetChildNodes(Type)for recursive search rather than manually iterating the tree. It searches the entire subtree. - Iterate direct children with
for child in nodewhen you only need immediate children. - Handle encoding on Windows: On Windows,
sys.stdoutmay use a legacy code page. Addsys.stdout.reconfigure(encoding="utf-8", errors="replace")at startup when printing Unicode text. - Install
[pdf]extra: PDF export requires ReportLab. Runpip install "aspose-note[pdf]"before usingSaveFormat.Pdf. Without ReportLab, saving to PDF raises anImportErrorat runtime.