Khởi động nhanh

Khởi động nhanh

Trang này đi qua các bước tối thiểu cần thiết để đọc OneNote. .one file và xuất nó sang PDF bằng cách sử dụng Aspose.Note FOSS for Python.


Prerequisites

RequirementDetail
Python3.10 or later
Packageaspose-note >= 26.3.2
OSWindows, macOS hoặc Linux
Microsoft OfficeKhông cần thiết

Bước 1 - Cài đặt

pip install aspose-note>=26.3.2

Bước 2 - Tải một tệp OneNote

Document là điểm đầu vào gốc. pass a .one file path để tải nó:

from aspose.note import Document

doc = Document("notebook.one")
print(f"Format : {doc.FileFormat}")
print(f"Pages  : {len(list(doc))}")

Bước 3 - Đọc Trang và Văn bản

GetChildNodes() trả về tất cả các người kế tiếp của một loại cụ thể. sử dụng nó trên Document trên các trang, và trên mỗi Page Đối với các nút giấy giàu văn bản:

from aspose.note import Document, Page, RichText

doc = Document("notebook.one")
for page in doc.GetChildNodes(Page):
    if page.Title and page.Title.TitleText:
        print(f"Page: {page.Title.TitleText}")
    for rt in page.GetChildNodes(RichText):
        text = "".join(rt)
        if text.strip():
            print(f"  {text[:120]}")

Bước 4 - Xuất sang PDF

Document.Save() Với SaveFormat.Pdf tạo PDF mà không có renderer bên ngoài:

from aspose.note import Document, SaveFormat

doc = Document("notebook.one")
doc.Save("output.pdf", SaveFormat.Pdf)

Bước tiếp theo

See Also

 Tiếng Việt