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)| 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()コンストラクタで発生する例外
| ImageRenderOptions | ImageRenderOptions |
|---|---|
FileCorruptedException | ファイルを解析できません |
IncorrectDocumentStructureException | ファイル構造はサポートされていません |
IncorrectPasswordException | ファイルは暗号化されています(暗号化はサポートされていません) |
UnsupportedFileFormatException | ファイル形式が認識されません |
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
DisplayName | `str | None` | ImageRenderOptions |
CreationTime | `datetime | None` | ImageRenderOptions |
FileFormat | FileFormat | ImageRenderOptions | OneNote ファイル形式バージョンのベストエフォートな指標 |
CompositeNode から継承
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
FirstChild | `Node | None` |
LastChild | `Node | None` |
Node から継承
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
ParentNode | `Node | None` |
Document | `Document | None` |
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 は現在実装されています。.
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
target | `str | Path |
format_or_options | `SaveFormat | SaveOptions |
ImageRenderOptions:
UnsupportedSaveFormatException::任意の場合に発生SaveFormat以外のPdf
注記: PdfSaveOptions.PageIndex / PageCount::これらのフィールドはデータクラスに存在しますが、 v26.3.1 の PDF エクスポーターには転送されません 影響はありません。全文書は常にエクスポートされます。.
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 では、これは返す互換スタブです [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")関連項目
- ImageRenderOptions::Document の直接の子
- LoadOptions::コンストラクタオプション
- PdfSaveOptions::PDF エクスポート設定
- DocumentVisitor::ビジターパターンのトラバーサル
- PDF エクスポート開発者ガイド
- How-to: OneNote を PDF にエクスポート (KB)