परिचय
यह मार्गदर्शिका दिखाती है कि कैसे PowerPoint प्रस्तुतियों को Python में प्रोग्रामेटिक रूप से बनाएं, संशोधित करें और सहेजें, Aspose.Slides FOSS का उपयोग करके। यह लाइब्रेरी आपको शून्य से स्लाइड्स बनाने, स्लाइड्स जोड़ने और क्रम बदलने, उन्हें आकार, तालिकाओं और स्वरूपित पाठ से भरने, और परिणाम को PPTX में सहेजने की सुविधा देती है। सभी प्रोसेसिंग शुद्ध Python में होती है, बिना Microsoft Office या किसी बाहरी बाइनरी पर निर्भरता के।
लाइब्रेरी PyPI पर aspose-slides-foss के रूप में MIT लाइसेंस के तहत उपलब्ध है। इसे pip के साथ स्थापित करें, आयात करें, और कुछ कोड पंक्तियों में प्रस्तुतियों का निर्माण शुरू करें। चाहे आप रिपोर्ट निर्माण को स्वचालित कर रहे हों, स्लाइड-डेक पाइपलाइन बना रहे हों, या वेब एप्लिकेशन में प्रस्तुति आउटपुट एम्बेड कर रहे हों, API पूरी कार्यक्षमता को कवर करता है: स्लाइड संग्रह, मास्टर/लेआउट स्लाइड्स, आकार संग्रह, टेक्स्ट फ्रेम, फ़िल फ़ॉर्मेट, और निर्यात विकल्प।
यह पोस्ट कोर प्रस्तुति-प्रबंधन क्षमताओं पर चलकर दिखाती है — वर्ग और विधियाँ जिन्हें आप Python में स्लाइड्स के साथ काम करते समय सबसे अधिक उपयोग करेंगे।
क्या शामिल है
प्रस्तुति जीवनचक्र
Presentation क्लास प्रवेश बिंदु है। एक नया डेक बनाएं, उसकी सामग्री को संशोधित करें, और PPTX में सहेजें। फ़ाइल हैंडल को स्वचालित रूप से रिलीज़ करने के लिए Presentation को with के साथ एक कॉन्टेक्स्ट मैनेजर के रूप में उपयोग करें।
import io
from aspose.slides_foss import Presentation
from aspose.slides_foss.export import SaveFormat
with Presentation() as pres:
# A new presentation starts with one blank slide
print("Slides:", len(pres.slides)) # 1
# Save to a file
pres.save("output.pptx", SaveFormat.PPTX)
# Or save to a stream
buf = io.BytesIO()
pres.save(buf, SaveFormat.PPTX)
स्लाइड संग्रह संचालन
SlideCollection आपको स्लाइड जोड़ने, सम्मिलित करने, क्लोन करने, हटाने और पुनः क्रमित करने की अनुमति देता है। len(pres.slides) प्रत्येक परिवर्तन के बाद वर्तमान गणना को दर्शाता है।
from aspose.slides_foss import Presentation, ShapeType
with Presentation() as pres:
layout = pres.layout_slides[0]
# Add a blank slide using the first layout
pres.slides.add_empty_slide(layout)
# Insert at a specific position
pres.slides.insert_empty_slide(1, layout)
# Clone an existing slide (shapes are copied)
pres.slides[0].shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 200, 100)
pres.slides.add_clone(pres.slides[0])
print("Total slides:", len(pres.slides)) # 4
# Remove by index
pres.slides.remove_at(3)
आकार और AutoShapes
किसी भी स्लाइड में आयत, दीर्घवृत्त, त्रिभुज और अन्य ज्यामितीय आकार ShapeCollection.add_auto_shape() के माध्यम से जोड़ें। प्रत्येक आकार स्थिति, आकार, घुमाव, और भराव गुण प्रदान करता है जो सहेजने/रीलोड करने के चक्रों में बना रहता है।
from aspose.slides_foss import Presentation, ShapeType
with Presentation() as pres:
slide = pres.slides[0]
slide.shapes.clear()
rect = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 300, 150)
rect.rotation = 15
ellipse = slide.shapes.add_auto_shape(ShapeType.ELLIPSE, 400, 50, 200, 200)
# Reorder z-index
slide.shapes.reorder(0, ellipse)
print("Front shape:", slide.shapes[0].shape_type) # ELLIPSE
टेबल्स
डेटा टेबल्स ShapeCollection.add_table() के साथ बनाएँ, सेल टेक्स्ट TextFrame के माध्यम से सेट करें, सेल्स को मिलाएँ, और बॉर्डर फ़ॉर्मेटिंग लागू करें। पंक्ति की ऊँचाई और कॉलम की चौड़ाई उन मानों से मेल खाती है जो आप कंस्ट्रक्टर को पास करते हैं।
from aspose.slides_foss import Presentation, FillType
from aspose.slides_foss.drawing import Color
with Presentation() as pres:
slide = pres.slides[0]
slide.shapes.clear()
table = slide.shapes.add_table(50, 50, [150, 150, 150], [40, 40, 40])
# Merge two cells in the second row
table.merge_cells(table.rows[1][0], table.rows[1][1], False)
# Style the header row with a bottom border
for col_idx in range(len(table.columns)):
fmt = table.rows[0][col_idx].cell_format
fmt.border_bottom.fill_format.fill_type = FillType.SOLID
fmt.border_bottom.fill_format.solid_fill_color.color = Color.from_argb(255, 0, 0, 0)
fmt.border_bottom.width = 2
मास्टर और लेआउट स्लाइड्स
प्रत्येक प्रस्तुति में मास्टर स्लाइड्स और लेआउट स्लाइड्स की एक पदानुक्रम होती है। उन्हें Presentation.masters और Presentation.layout_slides के माध्यम से एक्सेस करके आप अपने डेक में निरंतर फ़ॉर्मेटिंग लागू कर सकते हैं।
from aspose.slides_foss import Presentation
with Presentation() as pres:
master = pres.masters[0]
print("Master layouts:", len(master.layout_slides))
# Pick a layout by type
from aspose.slides_foss import SlideLayoutType
title_layout = pres.layout_slides.get_by_type(SlideLayoutType.TITLE)
if title_layout:
pres.slides.add_empty_slide(title_layout)
दस्तावेज़ गुण
शीर्षक, लेखक, और विषय जैसे अंतर्निहित मेटाडेटा को DocumentProperties ऑब्जेक्ट के माध्यम से पढ़ें और लिखें। save() को कॉल करने से पहले इन गुणों में से किसी को भी सेट करें — वे PPTX मेटाडेटा में एम्बेड होते हैं और डाउनस्ट्रीम टूल्स द्वारा पढ़े जा सकते हैं:
from aspose.slides_foss import Presentation
from aspose.slides_foss.export import SaveFormat
with Presentation() as pres:
props = pres.document_properties
props.title = "Quarterly Report"
props.author = "Engineering"
props.subject = "Q1 2026 Results"
pres.save("report.pptx", SaveFormat.PPTX)
त्वरित प्रारम्भ
निम्नलिखित pip कमांड चलाकर PyPI से Python के लिए Aspose.Slides FOSS स्थापित करें:
pip install aspose-slides-fossनिम्नलिखित उदाहरण एक प्रस्तुति बनाता है जिसमें शीर्षक आकार, डेटा तालिका, और भराव होता है, फिर इसे PPTX में सहेजता है:
from aspose.slides_foss import Presentation, ShapeType, FillType, NullableBool
from aspose.slides_foss.drawing import Color
from aspose.slides_foss.export import SaveFormat
with Presentation() as pres:
slide = pres.slides[0]
slide.shapes.clear()
# Add a title shape
title = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 30, 860, 80)
tf = title.add_text_frame("Quarterly Report")
tf.paragraphs[0].portions[0].portion_format.font_bold = NullableBool.TRUE
tf.paragraphs[0].portions[0].portion_format.font_height = 28
# Add a data table
table = slide.shapes.add_table(50, 150, [200, 200, 200], [40, 40, 40])
headers = ["Region", "Revenue", "Growth"]
for i, h in enumerate(headers):
table.rows[0][i].text_frame.text = h
# Fill the title shape background
title.fill_format.fill_type = FillType.SOLID
title.fill_format.solid_fill_color.color = Color.from_argb(255, 0, 51, 102)
# Save as PPTX
pres.save("report.pptx", SaveFormat.PPTX)
समर्थित स्वरूप
| फ़ॉर्मेट | विस्तार | पढ़ें | लिखें |
|---|---|---|---|
| PPTX | .pptx | ✓ | ✓ |
| PPT | .ppt | — | Planned |
| PPSX | .ppsx | — | Planned |
| PPTM | .pptm | — | Planned |
| POTX | .potx | — | Planned |
| ODP | .odp | — | Planned |
| — | Planned | ||
| HTML | .html | — | Planned |
| HTML5 | .html | — | Planned |
| TIFF | .tiff | — | Planned |
| GIF | .gif | — | Planned |
| XPS | .xps | — | Planned |
| FODP | .fodp | — | Planned |
| MD | .md | — | Planned |
नोट: PPTX पढ़ना और लिखना पूरी तरह से लागू किया गया है। अन्य SaveFormat मान (PPT, ODP, PDF, आदि) भविष्य के रिलीज़ के लिए योजना बनाये गए हैं; उन्हें पास करने पर save() वर्तमान में PPTX आउटपुट उत्पन्न करता है।
ओपन सोर्स एवं लाइसेंसिंग
Aspose.Slides FOSS for Python को MIT लाइसेंस के तहत जारी किया गया है। आप इसे व्यक्तिगत, शैक्षणिक और व्यावसायिक प्रोजेक्ट्स में बिना किसी प्रतिबंध के उपयोग कर सकते हैं। स्रोत कोड GitHub पर उपलब्ध है और पैकेज PyPI पर प्रकाशित किया गया है।