फ़ीचर अवलोकन — Aspose.Note FOSS for Python
Aspose.Note FOSS for Python (package aspose-note, संस्करण 26.3.1) Python API प्रदान करता है Microsoft OneNote पढ़ने के लिए .one सेक्शन फ़ाइलें और उन्हें PDF में निर्यात करना। नीचे सूचीबद्ध सभी सुविधाओं की पुष्टि रिपॉज़िटरी स्रोत कोड, README, और उदाहरण स्क्रिप्ट्स के विरुद्ध की गई है।.
स्थापना और सेटअप
PyPI से स्थापित करें:
pip install aspose-notePDF निर्यात समर्थन के लिए (ReportLab आवश्यक है):
pip install "aspose-note[pdf]"आवश्यकताएँ: Python 3.10 या बाद का संस्करण। Microsoft Office की स्थापना आवश्यक नहीं है।.
विशेषताएँ और क्षमताएँ
.one फ़ाइल लोडिंग
Microsoft OneNote सेक्शन फ़ाइलों को फ़ाइल पथ या किसी भी बाइनरी स्ट्रीम (फ़ाइल हैंडल, io.BytesIO, HTTP प्रतिक्रिया बॉडी, क्लाउड स्टोरेज स्ट्रीम)।.
Document.FileFormatOneNote फ़ाइल फ़ॉर्मेट संस्करण (OneNote2010, OneNoteOnline, या OneNote2007) का सर्वश्रेष्ठ प्रयास संकेत प्रदान करता है- स्ट्रीम-आधारित लोडिंग इन‑मेमोरी या नेटवर्क वर्कफ़्लो के लिए डिस्क I/O को समाप्त करती है
LoadOptions.LoadHistoryफ़्लैग नियंत्रित करता है कि पेज इतिहास DOM में शामिल हो या नहीं
from aspose.note import Document
##From a file path
doc = Document("notebook.one")
##From a binary stream
with open("notebook.one", "rb") as f:
doc = Document(f)डॉक्यूमेंट DOM ट्रैवर्सल
पूरा OneNote दस्तावेज़ टाइप्ड Python ऑब्जेक्ट्स के पेड़ के रूप में उजागर किया जाता है। प्रत्येक नोड विरासत में प्राप्त करता है Node या CompositeNode:
Document: रूट; उजागर करता हैDisplayName,CreationTime,FileFormatPage: का प्रत्यक्ष चाइल्डDocument; उजागर करता हैTitle,Author,CreationTime,LastModifiedTime,LevelTitle: उजागर करता हैTitleText,TitleDate,TitleTime(सभीRichTextनोड्स)Outline: स्थितीय कंटेनर जिसमेंHorizontalOffset,VerticalOffset,MaxWidth,MaxHeight,MinWidth,ReservedWidth,IndentPositionOutlineElement: लीफ़ कंटेनर; उजागर करता हैNumberList
नेविगेशन विधियाँ पर CompositeNode:
| विधि / गुण | विवरण |
|---|---|
FirstChild, LastChild | प्रत्यक्ष बाल पहुँच |
GetChildNodes(Type) | पुनरावर्ती, प्रकार-फ़िल्टर खोज |
AppendChildLast(node) | अंत में बाल जोड़ें |
AppendChildFirst(node) | शुरू में बाल जोड़ें |
InsertChild(index, node) | स्थिति पर सम्मिलित करें |
RemoveChild(node) | एक बाल हटाएँ |
for child in node | प्रत्यक्ष बच्चों पर पुनरावृति करें |
from aspose.note import Document, Page, Outline, OutlineElement, RichText
doc = Document("notebook.one")
for page in doc.GetChildNodes(Page):
title_text = page.Title.TitleText.Text if page.Title and page.Title.TitleText else ""
print(f"Page: {title_text}")
for outline in page.GetChildNodes(Outline):
for oe in outline.GetChildNodes(OutlineElement):
for rt in oe.GetChildNodes(RichText):
print(f" {rt.Text}")रिच टेक्स्ट सामग्री निष्कर्षण
RichText नोड्स प्रदर्शित करते हैं:
Text: str: पूर्ण साधारण-टेक्स्ट स्ट्रिंगTextRuns: list[TextRun]: स्वरूपित खंडों की सूचीTags: list[NoteTag]: इस ब्लॉक से जुड़े OneNote टैगAppend(text, style=None): मेमोरी में एक टेक्स्ट रन जोड़ेंReplace(old_value, new_value): मेमोरी में स्ट्रिंग प्रतिस्थापन
प्रत्येक TextRun धारण करता है:
| संपत्ति | प्रकार | विवरण |
|---|---|---|
Text | str | खंड पाठ |
Style | TextStyle | फ़ॉर्मेटिंग मेटाडेटा |
TextStyle गुण:
| गुण | प्रकार |
|---|---|
IsBold, IsItalic, IsUnderline, IsStrikethrough | bool |
IsSuperscript, IsSubscript | bool |
FontName | `str |
FontSize | `float |
FontColor, Highlight | `int |
Language | `int |
IsHyperlink | bool |
HyperlinkAddress | `str |
from aspose.note import Document, RichText
doc = Document("notebook.one")
for rt in doc.GetChildNodes(RichText):
for run in rt.TextRuns:
if run.Style.IsHyperlink:
print(f"Hyperlink: {run.Text} -> {run.Style.HyperlinkAddress}")
if run.Style.IsBold:
print(f"Bold text: {run.Text}")छवि निष्कर्षण
Image नोड्स प्रत्येक एम्बेडेड छवि के लिए कच्चे बाइट्स और मेटाडेटा उजागर करते हैं:
| गुण | प्रकार | विवरण |
|---|---|---|
FileName | `str | None` |
Bytes | bytes | कच्चा छवि डेटा |
Width, Height | `float | None` |
AlternativeTextTitle | `str | None` |
AlternativeTextDescription | `str | None` |
HyperlinkUrl | `str | None` |
Tags | list[NoteTag] | संलग्न OneNote टैग |
from aspose.note import Document, Image
doc = Document("notebook.one")
for i, img in enumerate(doc.GetChildNodes(Image), start=1):
filename = img.FileName or f"image_{i}.bin"
with open(filename, "wb") as f:
f.write(img.Bytes)
print(f"Saved: {filename} ({img.Width} x {img.Height} pts)")संलग्न फ़ाइल निष्कर्षण
AttachedFile नोड्स एम्बेडेड फ़ाइल अटैचमेंट्स को उजागर करते हैं:
| प्रॉपर्टी | प्रकार | विवरण |
|---|---|---|
FileName | `str | None` |
Bytes | bytes | कच्चा फ़ाइल डेटा |
Tags | list[NoteTag] | संलग्न OneNote टैग |
from aspose.note import Document, AttachedFile
doc = Document("notebook.one")
for i, af in enumerate(doc.GetChildNodes(AttachedFile), start=1):
filename = af.FileName or f"attachment_{i}.bin"
with open(filename, "wb") as f:
f.write(af.Bytes)तालिका पार्सिंग
Table, TableRow, और TableCell पूरी तालिका संरचना को उजागर करें:
| क्लास | मुख्य प्रॉपर्टी |
|---|---|
Table | Columns: list[TableColumn] (प्रत्येक TableColumn है .Width और .LockedWidth), IsBordersVisible: bool, Tags: list[NoteTag] |
TableRow | कोशिकाओं को इस माध्यम से दोहराएँ: GetChildNodes(TableCell) |
TableCell | शामिल है RichText, Image, और अन्य सामग्री नोड्स |
from aspose.note import Document, Table, TableRow, TableCell, RichText
doc = Document("notebook.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)
values = [
" ".join(rt.Text for rt in cell.GetChildNodes(RichText)).strip()
for cell in cells
]
print(f"Row {r}:", values)OneNote टैग निरीक्षण
NoteTag पर दिखाई देता है RichText, Image, AttachedFile, और Table उनके द्वारा नोड्स .Tags गुण।. OutlineElement के पास एक नहीं है .Tags गुण।. NoteTag गुण:
| गुण | प्रकार | विवरण |
|---|---|---|
Icon | `int | None` |
Label | `str | None` |
FontColor | `int | None` |
Highlight | `int | None` |
CreationTime | `datetime | None` |
CompletedTime | `datetime | None` |
फ़ैक्टरी मेथड: NoteTag.CreateYellowStar() एक मानक पीले-तारे वाला टैग नोड बनाता है।.
from aspose.note import Document, RichText
doc = Document("notebook.one")
for rt in doc.GetChildNodes(RichText):
for tag in rt.Tags:
print(f"Tag: {tag.Label} (icon={tag.Icon}, completed={tag.CompletedTime})")क्रमांकित सूची समर्थन
OutlineElement.NumberList प्रकट करता है:
| प्रॉपर्टी | प्रकार | विवरण |
|---|---|---|
Format | `str | None` |
Restart | `int | None` |
from aspose.note import Document, OutlineElement
doc = Document("notebook.one")
for oe in doc.GetChildNodes(OutlineElement):
nl = oe.NumberList
if nl:
print(f"format={nl.Format!r}")DocumentVisitor ट्रैवर्सल
DocumentVisitor संरचित पूर्ण-डॉक्यूमेंट ट्रैवर्सल के लिए विज़िटर पैटर्न प्रदान करता है। किसी भी को ओवरराइड करें VisitXxxStart / VisitXxxEnd विशिष्ट नोड प्रकारों को इंटरसेप्ट करने के लिए मेथड:
VisitDocumentStart(doc)/VisitDocumentEnd(doc)VisitPageStart(page)/VisitPageEnd(page)VisitTitleStart(title)/VisitTitleEnd(title)VisitOutlineStart(outline)/VisitOutlineEnd(outline)VisitOutlineElementStart(oe)/VisitOutlineElementEnd(oe)VisitRichTextStart(rt)/VisitRichTextEnd(rt)VisitImageStart(img)/VisitImageEnd(img)
from aspose.note import Document, DocumentVisitor, Page, RichText, Image
class MySummaryVisitor(DocumentVisitor):
def __init__(self):
self.pages, self.texts, self.images = 0, 0, 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("notebook.one")
v = MySummaryVisitor()
doc.Accept(v)
print(f"Pages={v.pages} RichText={v.texts} Images={v.images}")PDF निर्यात
लोड किए गए दस्तावेज़ को PDF में सहेजें, उपयोग करके Document.Save(). वैकल्पिक ReportLab बैकएंड के माध्यम से समर्थित।.
from aspose.note import Document, SaveFormat
doc = Document("notebook.one")
doc.Save("output.pdf", SaveFormat.Pdf)PdfSaveOptions
| विकल्प | प्रकार | विवरण |
|---|---|---|
PageIndex | int | फ़ील्ड मौजूद है; v26.3.1 में PDF एक्सपोर्टर को फ़ॉरवर्ड नहीं किया गया (कोई प्रभाव नहीं है) |
PageCount | `int | None` |
ImageCompression | `Any | None` |
JpegQuality | `int | None` |
PageSettings | `Any | None` |
PageSplittingAlgorithm | `Any | None` |
import io
from aspose.note import Document, SaveFormat
from aspose.note.saving import PdfSaveOptions
doc = Document("notebook.one")
##Save to file
doc.Save("output.pdf", SaveFormat.Pdf)
##Save to in-memory stream
buf = io.BytesIO()
doc.Save(buf, PdfSaveOptions())
pdf_bytes = buf.getvalue()फ़ॉर्मेट और एनीम रेफ़रेंस
SaveFormat
| मान | स्थिति |
|---|---|
SaveFormat.Pdf | लागू किया गया (ReportLab की आवश्यकता है) |
FileFormat
Document.FileFormat OneNote फ़ाइल फ़ॉर्मेट संस्करण का सर्वश्रेष्ठ‑प्रयास संकेत प्रदान करता है। enum तीन मान घोषित करता है:
| मान | विवरण |
|---|---|
FileFormat.OneNote2010 | OneNote 2010 फ़ॉर्मेट |
FileFormat.OneNoteOnline | OneNote Online फ़ॉर्मेट |
FileFormat.OneNote2007 | OneNote 2007 फ़ॉर्मेट |
NodeType
NodeType.Document, NodeType.Page, NodeType.Outline, NodeType.OutlineElement, NodeType.RichText, NodeType.Image, NodeType.Table, NodeType.AttachedFile
HorizontalAlignment
HorizontalAlignment.Left, HorizontalAlignment.Center, HorizontalAlignment.Right
वर्तमान सीमाएँ
| सीमा | विवरण |
|---|---|
| केवल‑पढ़ने योग्य | वापस लिखना .one फ़ॉर्मेट लागू नहीं किया गया है |
| कोई एन्क्रिप्शन नहीं | एन्क्रिप्टेड दस्तावेज़ त्रुटि उत्पन्न करते हैं IncorrectPasswordException |
| केवल निर्यात के लिए PDF | अन्य SaveFormat मान त्रुटि उत्पन्न करते हैं UnsupportedSaveFormatException |
| PDF के लिए ReportLab आवश्यक है | इंस्टॉल pip install "aspose-note[pdf]" अलग-अलग |
GetPageHistory एक-तत्वीय सूची लौटाता है | पूर्ण पृष्ठ इतिहास ट्रैवर्सल एक स्टब है; लौटाता है [page] |
DetectLayoutChanges() | संगतता स्टब; कोई ऑपरेशन नहीं |
टिप्स और सर्वोत्तम प्रथाएँ
- None के लिए जाँच करें:
Page.Title,Title.TitleText,OutlineElement.NumberList, और अधिकांश मेटाडेटा फ़ील्ड हो सकते हैंNone. हमेशा इसके साथ सुरक्षा करेंif x is not Noneयाif xगुणों तक पहुँचने से पहले।. - उपयोग करें
GetChildNodes(Type)पुनरावर्ती खोज के लिए, पेड़ को मैन्युअल रूप से इटररेट करने के बजाय। यह पूरे सबट्री को खोजता है।. - सीधे बच्चों को इटररेट करें के साथ
for child in nodeजब आपको केवल तत्काल बच्चों की आवश्यकता हो।. - Windows पर एन्कोडिंग संभालें: Windows पर,
sys.stdoutलेगेसी कोड पेज का उपयोग कर सकता है। जोड़ेंsys.stdout.reconfigure(encoding="utf-8", errors="replace")Unicode टेक्स्ट प्रिंट करते समय स्टार्टअप पर।. - इंस्टॉल करें
[pdf]अतिरिक्त: आयात न करेंSaveFormat.Pdfपहले इंस्टॉल किए बिना कार्यक्षमताpip install "aspose-note[pdf]". ReportLab के बिना, PDF में सहेजने पर रनटाइम में आयात त्रुटि उत्पन्न होगी।.