डेवलपर गाइड

Aspose.Note FOSS for Python is a free, open-source library for reading Microsoft OneNote .one section files बिना Microsoft Office पर किसी निर्भरता के। यह साफ़ public API प्रदान करता है under the aspose.note package, Aspose.Note for .NET interface के आधार पर मॉडल किया गया है। लाइब्रेरी दस्तावेज़ स्वचालन, सामग्री अनुक्रमण, डेटा निष्कर्षण पाइपलाइन, और अभिलेखीय कार्यप्रवाहों के लिए उपयुक्त है।.

यह डेवलपर गाइड संस्करण 26.3.1 में उपलब्ध पूर्ण सार्वजनिक API सतह को कवर करता है, जिसमें प्रत्येक प्रमुख सुविधा के लिए चलाने योग्य कोड उदाहरण शामिल हैं।.

दस्तावेज़ लोडिंग

लोड करें एक .one फ़ाइल को फ़ाइल पथ या binary stream से। यह Document class सभी ऑपरेशनों के लिए एंट्री पॉइंट है।.

फ़ाइल पथ से लोड करें

from aspose.note import Document

doc = Document("MyNotes.one")

बाइनरी स्ट्रीम से लोड करें

क्लाउड स्टोरेज, HTTP प्रतिक्रियाओं, या इन‑मेमोरी बफ़र्स से पढ़ते समय उपयोगी:

from pathlib import Path
from aspose.note import Document

with Path("MyNotes.one").open("rb") as f:
    doc = Document(f)

लोड विकल्प

उपयोग करें LoadOptions लोड समय पर वैकल्पिक पैरामीटर सेट करने के लिए:

from aspose.note import Document, LoadOptions

opts = LoadOptions()
opts.LoadHistory = True   # Include page history in the DOM
doc = Document("MyNotes.one", opts)

ध्यान दें: DocumentPassword पर मौजूद है LoadOptions API संगतता के लिए, लेकिन एन्क्रिप्टेड दस्तावेज़ समर्थित नहीं हैं। एन्क्रिप्टेड फ़ाइल लोड करने का प्रयास करने पर उत्पन्न होता है IncorrectPasswordException.


दस्तावेज़ संरचना (DOM)

OneNote दस्तावेज़ मॉडल एक ट्री (वृक्ष) है:

Document
  └── Page (0..n)
        ├── Title
        │     ├── TitleText (RichText)
        │     ├── TitleDate (RichText)
        │     └── TitleTime (RichText)
        └── Outline (0..n)
              └── OutlineElement (0..n)
                    ├── RichText
                    ├── Image
                    ├── Table
                    │     └── TableRow
                    │           └── TableCell
                    │                 └── RichText / Image
                    └── AttachedFile

प्रत्येक node एक्सपोज़ करता है ParentNode और एक Document प्रॉपर्टी जो रूट तक ऊपर जाती है। Composite nodes चाइल्ड इटरेशन का समर्थन करते हैं, FirstChild, LastChild, AppendChildLast, InsertChild, RemoveChild, और GetChildNodes(Type).


पृष्ठों पर इटरशन

Pages सीधे बच्चों हैं Document. उन्हें सीधे इटरेट करें या उपयोग करें GetChildNodes:

from aspose.note import Document, Page

doc = Document("MyNotes.one")

for page in doc:
    title = page.Title.TitleText.Text if page.Title and page.Title.TitleText else "(untitled)"
    author = page.Author or "(unknown)"
    print(f"  {title}  [by {author}]")

पृष्ठ मेटाडेटा:

संपत्तिप्रकारविवरण
Title`TitleNone`
Author`strNone`
CreationTime`datetimeNone`
LastModifiedTime`datetimeNone`
Level`intNone`

पाठ निष्कर्षण

सभी साधारण पाठ निकालें

from aspose.note import Document, RichText

doc = Document("MyNotes.one")
all_text = [rt.Text for rt in doc.GetChildNodes(RichText) if rt.Text]
print("\n".join(all_text))

फ़ॉर्मेटिंग रन की जाँच करें

प्रत्येक RichText में एक सूची शामिल है TextRun सेगमेंट। प्रत्येक रन अपना स्वयं का ले जाता है TextStyle:

from aspose.note import Document, RichText

doc = Document("FormattedNotes.one")
for rt in doc.GetChildNodes(RichText):
    for run in rt.TextRuns:
        style = run.Style
        flags = []
        if style.IsBold: flags.append("bold")
        if style.IsItalic: flags.append("italic")
        if style.IsHyperlink: flags.append(f"link={style.HyperlinkAddress}")
        print(f"{run.Text!r:40s} [{', '.join(flags)}]")

हाइपरलिंक निकालें

from aspose.note import Document, RichText

doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
    for run in rt.TextRuns:
        if run.Style.IsHyperlink and run.Style.HyperlinkAddress:
            print(run.Text, "->", run.Style.HyperlinkAddress)

छवि निष्कर्षण

from aspose.note import Document, Image

doc = Document("MyNotes.one")
for i, img in enumerate(doc.GetChildNodes(Image), start=1):
    name = img.FileName or f"image_{i}.bin"
    with open(name, "wb") as f:
        f.write(img.Bytes)
    print(f"Saved {name}  ({img.Width}x{img.Height})")

छवि गुण: FileName, Bytes, Width, Height, AlternativeTextTitle, AlternativeTextDescription, HyperlinkUrl, Tags.


तालिका पार्सिंग

from aspose.note import Document, Table, TableRow, TableCell, RichText

doc = Document("MyNotes.one")
for table in doc.GetChildNodes(Table):
    print("Column widths:", [col.Width for col in table.Columns])
    for r, row in enumerate(table.GetChildNodes(TableRow), start=1):
        cells = row.GetChildNodes(TableCell)
        row_text = [
            " ".join(rt.Text for rt in cell.GetChildNodes(RichText)).strip()
            for cell in cells
        ]
        print(f"Row {r}:", row_text)

संलग्न फ़ाइलें

from aspose.note import Document, AttachedFile

doc = Document("NotesWithAttachments.one")
for i, af in enumerate(doc.GetChildNodes(AttachedFile), start=1):
    name = af.FileName or f"attachment_{i}.bin"
    with open(name, "wb") as f:
        f.write(af.Bytes)
    print(f"Saved: {name}")

टैग और क्रमांकित सूचियाँ

NoteTag आइटम की जाँच करें

from aspose.note import Document, RichText, Image, Table

doc = Document("TaggedNotes.one")
for rt in doc.GetChildNodes(RichText):
    for tag in rt.Tags:
        print(f"RichText tag: {tag.Label} icon={tag.Icon}")
for img in doc.GetChildNodes(Image):
    for tag in img.Tags:
        print(f"Image tag: {tag.Label}")

क्रमांकित सूचियों की जाँच करें

from aspose.note import Document, OutlineElement

doc = Document("NumberedNotes.one")
for oe in doc.GetChildNodes(OutlineElement):
    nl = oe.NumberList
    if nl:
        print(f"format={nl.Format!r}")

DocumentVisitor पैटर्न

उपयोग करें DocumentVisitor एक विज़िटर लागू करने के लिए जो पूरे दस्तावेज़ वृक्ष को चलाता है:

from aspose.note import Document, DocumentVisitor, Page, RichText, Image

class ContentCounter(DocumentVisitor):
    def __init__(self):
        self.pages = 0
        self.texts = 0
        self.images = 0

    def VisitPageStart(self, page: Page) -> None:
        self.pages += 1

    def VisitRichTextStart(self, rt: RichText) -> None:
        self.texts += 1

    def VisitImageStart(self, img: Image) -> None:
        self.images += 1

doc = Document("MyNotes.one")
counter = ContentCounter()
doc.Accept(counter)
print(f"Pages: {counter.pages}, Texts: {counter.texts}, Images: {counter.images}")

PDF निर्यात

PDF निर्यात के लिए वैकल्पिक ReportLab निर्भरता आवश्यक है। इसे इस प्रकार स्थापित करें:

pip install "aspose-note[pdf]"

बेसिक PDF निर्यात

from aspose.note import Document, SaveFormat

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

विकल्पों के साथ PDF निर्यात

import io
from aspose.note import Document, SaveFormat
from aspose.note.saving import PdfSaveOptions

doc = Document("MyNotes.one")

##With save options
opts = PdfSaveOptions()
doc.Save("output.pdf", opts)

##Save to in-memory stream
buf = io.BytesIO()
doc.Save(buf, PdfSaveOptions())
pdf_bytes = buf.getvalue()

नोट: PdfSaveOptions.PageIndex और PageCount फ़ील्ड मौजूद हैं लेकिन v26.3.1 में PDF निर्यातकर्ता को अग्रेषित नहीं किए जाते। पूरा दस्तावेज़ हमेशा निर्यात किया जाता है।.


वर्तमान सीमाएँ

क्षेत्रस्थिति
पढ़ना .one फ़ाइलेंपूरी तरह समर्थित
PDF निर्यात (ReportLab के माध्यम से)समर्थित
वापस लिखना .oneलागू नहीं किया गया
एन्क्रिप्टेड दस्तावेज़समर्थित नहीं (उठाता है IncorrectPasswordException)
HTML / छवि / ONE सहेजने के फ़ॉर्मेटAPI संगतता के लिए घोषित; उठाएँ UnsupportedSaveFormatException

उपलब्ध गाइड्स


See Also

 हिन्दी