Document — Aspose.Note FOSS for Python API Reference
Sınıf: Document
Enumerations: aspose.note Enumerations: from aspose.note import Document Enumerations: CompositeNode
Document OneNote belge nesne modelinin kök düğümüdür. Tek bir OneNote bölüm dosyasını temsil eder (.one) Document.
Enumerations
Document(source=None, load_options=None)| Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|
source | `str | Path | BinaryIO |
load_options | `LoadOptions | None` | 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()Yapıcı tarafından yükseltilen istisnalar
| Enumerations | Enumerations |
|---|---|
FileCorruptedException | Dosya ayrıştırılamıyor |
IncorrectDocumentStructureException | Dosya yapısı desteklenmiyor |
IncorrectPasswordException | Dosya şifrelenmiş (şifreleme desteklenmiyor) |
UnsupportedFileFormatException | Dosya formatı tanınmıyor |
Enumerations
| Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|
DisplayName | `str | None` | Enumerations |
CreationTime | `datetime | None` | Enumerations |
FileFormat | FileFormat | Enumerations | OneNote dosya formatı sürümünün en iyi çaba ile gösterimi |
CompositeNode’dan kalıtılmış
| Enumerations | Enumerations | Enumerations |
|---|---|---|
FirstChild | `Node | None` |
LastChild | `Node | None` |
Node’dan miras alındı
| Enumerations | Enumerations | Enumerations |
|---|---|---|
ParentNode | `Node | None` |
Document | `Document | None` |
Enumerations
Count()
len(list(doc)) -> intDoğrudan alt öğe sayısını döndürür Page düğümler (yani, bölümdeki sayfa sayısı).
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) -> NoneBelgeyi bir dosya yoluna kaydeder, pathlib.Path, ya da bir ikili akışa. Yalnızca SaveFormat.Pdf şu anda uygulanmıştır.
| Enumerations | Enumerations | Enumerations |
|---|---|---|
target | `str | Path |
format_or_options | `SaveFormat | SaveOptions |
Enumerations:
UnsupportedSaveFormatException: herhangi bir şey için yükseltilirSaveFormatdışındaPdf
Not PdfSaveOptions.PageIndex / PageCount: Bu alanlar dataclass içinde var ancak v26.3.1’de PDF dışa aktarıcısına iletilmez ve hiçbir etkisi yoktur. Tam belge her zaman dışa aktarılır.
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) -> NoneZiyaretçiyi tüm belge ağacını dolaşması için gönderir. Çağırır visitor.VisitDocumentStart(self), ardından tüm alt düğümleri özyinelemeli olarak ziyaret eder.
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]Bir sayfanın sürüm geçmişini döndürür. v26.3.1’de, bu, döndüren bir uyumluluk taslağıdır [page].
DetectLayoutChanges()
doc.DetectLayoutChanges() -> NoneUyumluluk taslağı. İşlem yok.
Enumerations
for page in doc:
...Doğrudan alt çocuğu yineleyerek dolaşır Page belge sırasındaki düğümler.
Tam Örnek
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")Ayrıca Bakınız
- Enumerations: Document’in doğrudan çocuğu
- LoadOptions: yapıcı seçenekleri
- PdfSaveOptions: PDF dışa aktarma yapılandırması
- DocumentVisitor: visitor-pattern gezinme
- PDF Dışa Aktarma Geliştirici Kılavuzu
- Nasıl Yapılır: OneNote’u PDF’ye Dışa Aktarma (KB)