Document — Aspose.Note FOSS for Python API Reference
Classe : Document
Examples: aspose.note Examples: from aspose.note import Document Examples: CompositeNode
Document est le nœud racine du modèle d’objet de document OneNote. Il représente un seul fichier de section OneNote (.one) Document.
Examples
Document(source=None, load_options=None)| Examples | Examples | Examples | Examples |
|---|---|---|---|
source | `str | Path | BinaryIO |
load_options | `LoadOptions | None` | Examples |
Examples
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()Exceptions levées par le constructeur
| Examples | Examples |
|---|---|
FileCorruptedException | Le fichier ne peut pas être analysé |
IncorrectDocumentStructureException | La structure du fichier n’est pas prise en charge |
IncorrectPasswordException | Le fichier est chiffré (chiffrement non pris en charge) |
UnsupportedFileFormatException | Le format du fichier n’est pas reconnu |
Examples
| Examples | Examples | Examples | Examples |
|---|---|---|---|
DisplayName | `str | None` | Examples |
CreationTime | `datetime | None` | Examples |
FileFormat | FileFormat | Examples | Indication approximative de la version du format de fichier OneNote |
Hérité de CompositeNode
| Examples | Examples | Examples |
|---|---|---|
FirstChild | `Node | None` |
LastChild | `Node | None` |
Hérité de Node
| Examples | Examples | Examples |
|---|---|---|
ParentNode | `Node | None` |
Document | `Document | None` |
Examples
Count()
len(list(doc)) -> intRenvoie le nombre d’enfants directs Page nœuds (c’est‑à‑dire le nombre de pages dans la section).
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) -> NoneEnregistre le document à un chemin de fichier, pathlib.Path, ou un flux binaire. Seulement SaveFormat.Pdf est actuellement implémenté.
| Examples | Examples | Examples |
|---|---|---|
target | `str | Path |
format_or_options | `SaveFormat | SaveOptions |
Examples:
UnsupportedSaveFormatException: levé pour toutSaveFormatautre quePdf
Note sur PdfSaveOptions.PageIndex / PageCount: Ces champs existent dans la dataclass mais sont non transmis à l’exportateur PDF dans la v26.3.1 et n’ont aucun effet. Le document complet est toujours exporté.
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) -> NoneDéclenche le visiteur pour parcourir l’arbre complet du document. Appelle visitor.VisitDocumentStart(self), puis visite récursivement tous les nœuds enfants.
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]Renvoie l’historique des versions d’une page. Dans la v26.3.1, il s’agit d’un stub de compatibilité qui renvoie [page].
DetectLayoutChanges()
doc.DetectLayoutChanges() -> NoneStub de compatibilité. Aucune opération.
Examples
for page in doc:
...Itère l’enfant direct Page nœuds dans l’ordre du document.
Exemple complet
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")Voir aussi
- Examples: enfant direct de Document
- LoadOptions: options du constructeur
- PdfSaveOptions: configuration d’export PDF
- DocumentVisitor: traversée du pattern visiteur
- Guide du développeur pour l’exportation PDF
- Comment faire: Exporter OneNote en PDF (KB)