Document

Document — Aspose.Note FOSS for Python API Reference

کلاس: Document

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

Document ریشه گره مدل شیء سند OneNote است. این یک فایل بخش تک‌تک OneNote را نمایندگی می‌کند (.one). تمام صفحات فرزندان مستقیم 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()

استثناهای ایجاد شده توسط سازنده

ImageRenderOptionsImageRenderOptions
FileCorruptedExceptionفایل قابل تجزیه نیست
IncorrectDocumentStructureExceptionساختار فایل پشتیبانی نمی‌شود
IncorrectPasswordExceptionفایل رمزگذاری شده است (رمزگذاری پشتیبانی نمی‌شود)
UnsupportedFileFormatExceptionقالب فایل شناسایی نشد

ImageRenderOptions

ImageRenderOptionsImageRenderOptionsImageRenderOptionsImageRenderOptions
DisplayName`strNone`ImageRenderOptions
CreationTime`datetimeNone`ImageRenderOptions
FileFormatFileFormatImageRenderOptionsنشانه‌گذاری با بیشترین تلاش برای نسخهٔ قالب فایل OneNote

ارث‌بری شده از CompositeNode

ImageRenderOptionsImageRenderOptionsImageRenderOptions
FirstChild`NodeNone`
LastChild`NodeNone`

ارث‌بری شده از Node

ImageRenderOptionsImageRenderOptionsImageRenderOptions
ParentNode`NodeNone`
Document`DocumentNone`

ImageRenderOptions

Count()

len(list(doc)) -> int

تعداد فرزندان مستقیم را برمی‌گرداند Page گره‌ها (یعنی تعداد صفحات در بخش).

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

سند را در مسیر فایل ذخیره می‌کند،, pathlib.Path,، یا یک جریان باینری. فقط SaveFormat.Pdf در حال حاضر پیاده‌سازی شده است.

ImageRenderOptionsImageRenderOptionsImageRenderOptions
target`strPath
format_or_options`SaveFormatSaveOptions

ImageRenderOptions:

  • UnsupportedSaveFormatException: برای هر SaveFormat غیر از Pdf

توجه به PdfSaveOptions.PageIndex / PageCount: این فیلدها در دیتاکلاس وجود دارند اما هستند به صادرکننده PDF در v26.3.1 ارسال نمی‌شود و هیچ تأثیری ندارند. سند کامل همیشه صادر می‌شود.

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

بازدیدکننده را برای پیمایش کل درخت سند ارسال می‌کند. فراخوانی می‌کند visitor.VisitDocumentStart(self),، سپس به‌صورت بازگشتی تمام گره‌های فرزند را بازدید می‌کند.

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]

تاریخچه نسخه‌های یک صفحه را برمی‌گرداند. در v26.3.1، این یک stub سازگاری است که برمی‌گرداند [page].


DetectLayoutChanges()

doc.DetectLayoutChanges() -> None

استاب سازگاری. هیچ عملی انجام نمی‌دهد.


ImageRenderOptions

for page in doc:
    ...

فرزند مستقیم را تکرار می‌کند Page گره‌ها را به ترتیب سند.


مثال کامل

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

همچنین ببینید

 فارسی