Document — Aspose.Note FOSS for Python API Reference
Klasse: Document
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import Document ImageRenderOptions: CompositeNode
Document is de rootnode van het OneNote‑documentobjectmodel. Het vertegenwoordigt een enkel OneNote‑sectiebestand..one). Alle pagina’s zijn directe kinderen van Document.
ImageRenderOptions
Document(source=None, load_options=None)| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
source | `str | Path | BinaryIO |
load_options | `LoadOptions | None` | ImageRenderOptions |
ImageRenderOptions
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()Uitzonderingen die door de constructor worden opgegooid
| ImageRenderOptions | ImageRenderOptions |
|---|---|
FileCorruptedException | Het bestand kan niet worden geparseerd |
IncorrectDocumentStructureException | De bestandstructuur wordt niet ondersteund |
IncorrectPasswordException | Het bestand is versleuteld (versleuteling niet ondersteund) |
UnsupportedFileFormatException | Het bestandsformaat wordt niet herkend |
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
DisplayName | `str | None` | ImageRenderOptions |
CreationTime | `datetime | None` | ImageRenderOptions |
FileFormat | FileFormat | ImageRenderOptions | Best‑effort indicatie van de OneNote‑bestandformaatversie |
Geërfd van CompositeNode
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
FirstChild | `Node | None` |
LastChild | `Node | None` |
Geërfd van Node
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
ParentNode | `Node | None` |
Document | `Document | None` |
ImageRenderOptions
Count()
len(list(doc)) -> intRetourneert het aantal directe child Page nodes (d.w.z. het aantal pagina’s in de sectie).
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) -> NoneSlaat het document op naar een bestandspad, pathlib.Path, of een binaire stream. Alleen SaveFormat.Pdf is momenteel geïmplementeerd.
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
target | `str | Path |
format_or_options | `SaveFormat | SaveOptions |
ImageRenderOptions:
UnsupportedSaveFormatException: opgeworpen voor elkeSaveFormatanders danPdf
Opmerking over PdfSaveOptions.PageIndex / PageCount: Deze velden bestaan in de dataklasse maar zijn niet doorgestuurd naar de PDF-exporteur in v26.3.1 en hebben geen effect. Het volledige document wordt altijd geëxporteerd.
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) -> NoneStuurt de visitor aan om de volledige documentboom te doorlopen. Roept visitor.VisitDocumentStart(self), en bezoekt vervolgens recursief alle kindknopen.
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]Retourneert de versiegeschiedenis van een pagina. In v26.3.1 is dit een compatibiliteitsstub die retourneert [page].
DetectLayoutChanges()
doc.DetectLayoutChanges() -> NoneCompatibiliteitsstub. Geen bewerking.
ImageRenderOptions
for page in doc:
...Itereert over het directe kind Page knooppunten in documentvolgorde.
Volledig voorbeeld
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")Zie ook
- ImageRenderOptions: direct kind van Document
- LoadOptions: constructoropties
- PdfSaveOptions: PDF-exportconfiguratie
- DocumentVisitor: visitor-pattern traversal
- PDF-exportontwikkelaarsgids
- Handleiding: OneNote exporteren naar PDF (KB)