Document

Document — Aspose.Note FOSS for Python API Reference

Клас: Document

Enumerations: aspose.note Enumerations: from aspose.note import Document Enumerations: CompositeNode

Document є кореневим вузлом об’єктної моделі документа OneNote. Він представляє окремий файл розділу OneNote (.one). Усі сторінки є прямими нащадками Document.


Enumerations

Document(source=None, load_options=None)
EnumerationsEnumerationsEnumerationsEnumerations
source`strPathBinaryIO
load_options`LoadOptionsNone`Enumerations

Enumerations

from aspose.note import Document

##Load from a file path
doc = Document("MyNotes.one")

##Load from a binary stream
with open("MyNotes.one", "rb") as f:
    doc = Document(f)

##Empty document (no source file)
doc = Document()

Винятки, які піднімаються конструктором

EnumerationsEnumerations
FileCorruptedExceptionФайл не може бути розпарсений
IncorrectDocumentStructureExceptionСтруктура файлу не підтримується
IncorrectPasswordExceptionФайл зашифрований (шифрування не підтримується)
UnsupportedFileFormatExceptionФормат файлу не розпізнано

Enumerations

EnumerationsEnumerationsEnumerationsEnumerations
DisplayName`strNone`Enumerations
CreationTime`datetimeNone`Enumerations
FileFormatFileFormatEnumerationsНайкраща можлива вказівка версії формату файлу OneNote

Успадковано від CompositeNode

EnumerationsEnumerationsEnumerations
FirstChild`NodeNone`
LastChild`NodeNone`

Успадковано від Node

EnumerationsEnumerationsEnumerations
ParentNode`NodeNone`
Document`DocumentNone`

Enumerations

Count()

len(list(doc)) -> int

Повертає кількість безпосередніх дочірніх Page вузлів (тобто кількість сторінок у розділі).

from aspose.note import Document

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

Save(target, format_or_options)

doc.Save(target: str | Path | BinaryIO, format_or_options: SaveFormat | SaveOptions | None = None) -> None

Зберігає документ у шлях файлу, pathlib.Path, або у бінарний потік. Лише SaveFormat.Pdf на даний момент реалізовано.

EnumerationsEnumerationsEnumerations
target`strPath
format_or_options`SaveFormatSaveOptions

Enumerations:

  • UnsupportedSaveFormatException: піднімається для будь‑якого SaveFormat крім Pdf

Примітка щодо PdfSaveOptions.PageIndex / PageCount: Ці поля існують у dataclass, але є не передаються експортеру PDF у v26.3.1 і не мають жодного впливу. Повний документ завжди експортується.

import io
from aspose.note import Document, SaveFormat, PdfSaveOptions

doc = Document("MyNotes.one")

##Save to file path (string)
doc.Save("output.pdf", SaveFormat.Pdf)

##Save to a pathlib.Path
from pathlib import Path
doc.Save(Path("output.pdf"), SaveFormat.Pdf)

##Save to an in-memory stream
buf = io.BytesIO()
doc.Save(buf, PdfSaveOptions(SaveFormat.Pdf))
pdf_bytes = buf.getvalue()

Accept(visitor)

doc.Accept(visitor: DocumentVisitor) -> None

Відправляє відвідувача для обходу всього дерева документу. Викликає visitor.VisitDocumentStart(self), а потім рекурсивно відвідує всі дочірні вузли.

from aspose.note import Document, DocumentVisitor

class MyVisitor(DocumentVisitor):
    def VisitDocumentStart(self, doc):
        print(f"Document: {doc.DisplayName}")

doc = Document("MyNotes.one")
doc.Accept(MyVisitor())

GetPageHistory(page)

doc.GetPageHistory(page: Page) -> list[Page]

Повертає історію версій сторінки. У v26.3.1 це сумісна заглушка, яка повертає [page].


DetectLayoutChanges()

doc.DetectLayoutChanges() -> None

Заглушка сумісності. Операція не виконується.


Enumerations

for page in doc:
    ...

Ітерує прямого дочірнього вузла Page вузли у порядку документа.


Повний приклад

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

doc = Document("MyNotes.one")

print(f"Section: {doc.DisplayName}")
print(f"Format:  {doc.FileFormat}")
print(f"Created: {doc.CreationTime}")
print(f"Pages:   {len(list(doc))}")

for page in doc:
    title = page.Title.TitleText.Text if page.Title and page.Title.TitleText else "(untitled)"
    texts = page.GetChildNodes(RichText)
    print(f"  [{title}]  {len(texts)} text node(s)")

doc.Save("output.pdf", SaveFormat.Pdf)
print("Saved output.pdf")

Див. також

 Українська