مقدمة

Aspose.Note FOSS for Python (aspose-note على PyPI) هو مكتبة مجانية ومعتمدة من قبل MIT ل اقرأ مايكروسوفت OneNote .one الملفات وتصديرها إلى PDF في Python النقي. الإصدار 26.3.2 السفن مع نموذج كامل من مستندات الكائنات تغطي الصفحات والخطوط النشرية وعقد النص الغني والصور،, المرفقات – لا تُطلب إعداد Microsoft Office أو إدمان Windows.


الميزات الرئيسية

تحميل الوثائق وتحديد تنسيقها

Document هو جذر نموذج الكائن.مر مسار الملف لتحميل أي OneNote مدعوم النموذج : The FileFormat التقارير الممتلكات التي تم اكتشافها في شكل.

from aspose.note import Document, FileFormat

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

نقل الصفحات واللقائح

الصفحات هي Page يقع في المرتبة تحت Document.كل واحد منهم Page يقدم هذا النوع من البيانات الميتا كما Author, CreationTime,و ، و Title.- من Title ويدخل النود في المقابل TitleText, TitleDate,و ، و TitleTime كما RichText الأطفال .

from aspose.note import Document, Page

doc = Document("notebook.one")
for page in doc.GetChildNodes(Page):
    print(f"Author  : {page.Author}")
    print(f"Created : {page.CreationTime}")
    if page.Title and page.Title.TitleText:
        print(f"Title   : {page.Title.TitleText}")

قراءة محتوى النص الغني

RichText العقد هي العقود الورقية التي تحمل محتوى النص الحقيقي. RichText موضوع مع معايير for الرافعة - كل عنصر هو قطاع الحبل.استخدام Append() إضافة إلى نص جديد مع نمط.

from aspose.note import Document, Page, Outline, RichText

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

خصائص Outline Layout

Outline يظهر العقد إحداثيات التصميم: HorizontalOffset, VerticalOffset, MaxWidth, MaxHeight,و ، و MinWidth.هذه مفيدة لخروج الوعي التخطيط أو إعادة ترتيب الصفحات.

from aspose.note import Document, Outline

doc = Document("notebook.one")
for outline in doc.GetChildNodes(Outline):
    print(f"HOffset={outline.HorizontalOffset}  VOffset={outline.VerticalOffset}  MaxW={outline.MaxWidth}")

وثيقة الخشب البناء

بناء أ Document من سكراتش باستخدام CompositeNode.AppendChildLast().كل نوع من النقاط يمكن إضافةها إلى الوالدين المعمول به: PageDocument, OutlinePage, RichText النود Outline.

from aspose.note import Document, Page, Outline, RichText, ParagraphStyle, Title, SaveFormat

doc = Document()
page = Page()

title_text = RichText()
title_text.Append("My New Page", ParagraphStyle())
title = Title()
title.TitleText = title_text
page.Title = title

outline = Outline()
page.AppendChildLast(outline)
doc.AppendChildLast(page)
doc.Save("new_notebook.pdf", SaveFormat.Pdf)

تصدير إلى PDF

Document.Save() قبول SaveFormat.Pdf كتابة PDF إلى مسار ملف أو أ أ BytesIO يُنقل التصدير تماماً في العملية دون أي إصدار خارجي.

import io
from aspose.note import Document, SaveFormat

doc = Document("notebook.one")

# File output
doc.Save("export.pdf", SaveFormat.Pdf)

# In-memory buffer
buf = io.BytesIO()
doc.Save(buf, SaveFormat.Pdf)
print(f"PDF bytes: {len(buf.getvalue())}")

بدء سريع

pip install aspose-note
from aspose.note import Document, Page, RichText, SaveFormat

doc = Document("notebook.one")

# Print all text
for page in doc.GetChildNodes(Page):
    for rt in page.GetChildNodes(RichText):
        print("".join(rt))

# Export to PDF
doc.Save("output.pdf", SaveFormat.Pdf)

تنسيقات مدعومة

شكلالتمديدقراءةكتب
OneNote 2010.one
OneNote 2007.one
OneNote على الانترنت.one
PDF.pdf

المصدر المفتوح و الترخيص

Aspose.Note FOSS for Python is released under the MIT License. Install from PyPI as aspose-note.- الاستخدام التجاري، وإعادة التوزيع والتعديل مسموح به.


بدءاً من