Document — Aspose.Note FOSS for Python API Reference
Clasa: Document
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import Document ImageRenderOptions: CompositeNode
Document este nodul rădăcină al modelului de obiecte al documentului OneNote. Reprezintă un singur fișier de secțiune OneNote (.one). All pages are direct children of 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()Excepții ridicate de constructor
| ImageRenderOptions | ImageRenderOptions |
|---|---|
FileCorruptedException | Fișierul nu poate fi analizat |
IncorrectDocumentStructureException | Structura fișierului nu este suportată |
IncorrectPasswordException | Fișierul este criptat (criptarea nu este suportată) |
UnsupportedFileFormatException | Formatul fișierului nu este recunoscut |
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
DisplayName | `str | None` | ImageRenderOptions |
CreationTime | `datetime | None` | ImageRenderOptions |
FileFormat | FileFormat | ImageRenderOptions | Indicație în limita posibilităților a versiunii formatului de fișier OneNote |
Moștenit de la CompositeNode
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
FirstChild | `Node | None` |
LastChild | `Node | None` |
Moștenit de la Node
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
ParentNode | `Node | None` |
Document | `Document | None` |
ImageRenderOptions
Count()
len(list(doc)) -> intReturnează numărul de copii direcți Page noduri (adică numărul de pagini din secțiune).
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) -> NoneSalvează documentul într-o cale de fișier, pathlib.Path, sau un flux binar. Doar SaveFormat.Pdf este implementat în prezent.
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
target | `str | Path |
format_or_options | `SaveFormat | SaveOptions |
ImageRenderOptions:
UnsupportedSaveFormatException: ridicat pentru oriceSaveFormataltul decâtPdf
Notă despre PdfSaveOptions.PageIndex / PageCount: Aceste câmpuri există în clasa de date, dar sunt nu sunt transmise exportatorului PDF în v26.3.1 și nu au niciun efect. Documentul complet este întotdeauna exportat.
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) -> NoneTrimite vizitatorul să parcurgă întregul arbore al documentului. Apelează visitor.VisitDocumentStart(self), apoi vizitează recursiv toate nodurile copil.
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]Returnează istoricul versiunilor unei pagini. În v26.3.1, acesta este un stub de compatibilitate care returnează [page].
DetectLayoutChanges()
doc.DetectLayoutChanges() -> NoneStub de compatibilitate. Nicio operație.
ImageRenderOptions
for page in doc:
...Iterează copilul direct Page nodurile în ordine de document.
Exemplu 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")Vezi și
- ImageRenderOptions: copil direct al Documentului
- LoadOptions: opțiuni ale constructorului
- PdfSaveOptions: configurare export PDF
- DocumentVisitor: traversare în stil visitor-pattern
- Ghid pentru dezvoltatori Export PDF
- Instrucțiuni: Export OneNote în PDF (KB)