Document

Document — Aspose.Note FOSS for Python API Reference

Classe: Document

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

Document è il nodo radice del modello a oggetti del documento OneNote. Rappresenta un singolo file di sezione OneNote (.one). Tutte le pagine sono figli diretti di Document.


ImageRenderOptions

Document(source=None, load_options=None)
ImageRenderOptionsImageRenderOptionsImageRenderOptionsImageRenderOptions
source`strPathBinaryIO
load_options`LoadOptionsNone`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()

Eccezioni sollevate dal costruttore

ImageRenderOptionsImageRenderOptions
FileCorruptedExceptionIl file non può essere analizzato
IncorrectDocumentStructureExceptionLa struttura del file non è supportata
IncorrectPasswordExceptionIl file è crittografato (crittografia non supportata)
UnsupportedFileFormatExceptionIl formato del file non è riconosciuto

ImageRenderOptions

ImageRenderOptionsImageRenderOptionsImageRenderOptionsImageRenderOptions
DisplayName`strNone`ImageRenderOptions
CreationTime`datetimeNone`ImageRenderOptions
FileFormatFileFormatImageRenderOptionsIndicazione approssimativa della versione del formato file OneNote

Ereditato da CompositeNode

ImageRenderOptionsImageRenderOptionsImageRenderOptions
FirstChild`NodeNone`
LastChild`NodeNone`

Ereditato da Node

ImageRenderOptionsImageRenderOptionsImageRenderOptions
ParentNode`NodeNone`
Document`DocumentNone`

ImageRenderOptions

Count()

len(list(doc)) -> int

Restituisce il numero di figli diretti Page nodi (cioè, il numero di pagine nella sezione).

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

Salva il documento in un percorso file, pathlib.Path, o un flusso binario. Solo SaveFormat.Pdf è attualmente implementato.

ImageRenderOptionsImageRenderOptionsImageRenderOptions
target`strPath
format_or_options`SaveFormatSaveOptions

ImageRenderOptions:

  • UnsupportedSaveFormatException: sollevato per qualsiasi SaveFormat diverso da Pdf

Nota su PdfSaveOptions.PageIndex / PageCount: Questi campi esistono nella dataclass ma sono non inoltrati all’esportatore PDF nella v26.3.1 e non hanno alcun effetto. Il documento completo è sempre esportato.

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

Inoltra il visitatore per attraversare l’intero albero del documento. Chiama visitor.VisitDocumentStart(self), quindi visita ricorsivamente tutti i nodi figli.

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]

Restituisce la cronologia delle versioni di una pagina. Nella v26.3.1, questo è un stub di compatibilità che restituisce [page].


DetectLayoutChanges()

doc.DetectLayoutChanges() -> None

Stub di compatibilità. Nessuna operazione.


ImageRenderOptions

for page in doc:
    ...

Itera il figlio diretto Page nodi in ordine di documento.


Esempio completo

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")

Vedi anche

 Italiano