Document

الفئة: Document

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

Document هو العقدة الجذرية لنموذج كائن مستند OneNote. يمثل ملف قسم OneNote واحد (.one). Document.


Properties

Document(source=None, load_options=None)
PropertiesPropertiesPropertiesProperties
source`strPathBinaryIO
load_options`LoadOptionsNone`Properties

Properties

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

الاستثناءات التي يثيرها المُنشئ

PropertiesProperties
FileCorruptedExceptionلا يمكن تحليل الملف
IncorrectDocumentStructureExceptionبنية الملف غير مدعومة
IncorrectPasswordExceptionالملف مشفر (التشفير غير مدعوم)
UnsupportedFileFormatExceptionلم يتم التعرف على تنسيق الملف

Properties

PropertiesPropertiesPropertiesProperties
DisplayName`strNone`Properties
CreationTime`datetimeNone`Properties
FileFormatFileFormatPropertiesإشارة بأقصى جهد لإصدار تنسيق ملف OneNote

موروث من CompositeNode

PropertiesPropertiesProperties
FirstChild`NodeNone`
LastChild`NodeNone`

موروث من Node

PropertiesPropertiesProperties
ParentNode`NodeNone`
Document`DocumentNone`

Properties

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 مُنفَّذ حاليًا.

PropertiesPropertiesProperties
target`strPath
format_or_options`SaveFormatSaveOptions

Properties:

  • UnsupportedSaveFormatException: يُرفع لأي SaveFormat غير Pdf

ملاحظة حول PdfSaveOptions.PageIndex / PageCount: هذه الحقول موجودة في الـ dataclass لكنها لم يتم إرساله إلى مُصدّر 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

دالة توافقية. لا عملية.


Properties

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

انظر أيضًا

 العربية