เริ่มต้นอย่างรวดเร็ว
เริ่มต้นอย่างรวดเร็ว
หน้านี้จะนําไปใช้ขั้นตอนที่จําเป็นในการอ่าน OneNote .one รายการและ นําออกเป็น PDF โดยใช้ Aspose.Note FOSS สําหรับ Python.
Prerequisites
| Requirement | Detail |
|---|---|
| Python | 3.10 or later |
| Package | aspose-note >= 26.3.2 |
| OS | Windows, macOS หรือ Linux |
| Microsoft Office (สํานักงาน) | ไม่จําเป็น |
ขั้นตอน 1 ติดตั้ง
pip install aspose-note>=26.3.2ขั้นตอน 2 อัตราการอัพโหลดไฟล์ OneNote
Document คือจุดเข้าราก. .one เส้นทางไฟล์ในการอัตราบรรจุ:
from aspose.note import Document
doc = Document("notebook.one")
print(f"Format : {doc.FileFormat}")
print(f"Pages : {len(list(doc))}")ขั้นตอน 3 อ่าน หน้า และ ข้อความ
GetChildNodes() กลับผลลัพธ์ตรงทั้งหมดของชนิดที่ให้. ใช้มันใน Document สําหรับหน้า และบนแต่ละ หน้า Page สําหรับหน่วยใบที่มีบทความร่ํารวย:
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]}")ขั้นตอน 4 การส่งออกเป็น PDF
Document.Save() มี SaveFormat.Pdf สร้าง PDF โดยไม่ต้องใช้เครื่องทําการแสดงภาพภายนอก:
from aspose.note import Document, SaveFormat
doc = Document("notebook.one")
doc.Save("output.pdf", SaveFormat.Pdf)