Python के माध्यम से Java में PowerPoint टेक्स्ट पैराग्राफ का प्रबंधन
अवलोकन
Aspose.Slides for Python via Java टेक्स्ट को टेक्स्ट फ्रेम, पैराग्राफ और पोर्शन की पदानुक्रम में प्रस्तुत करता है:
- TextFrame shape में टेक्स्ट कंटेनर का प्रतिनिधित्व करता है और इसके पैराग्राफ संग्रह तक पहुँच प्रदान करता है।
- Paragraph टेक्स्ट फ्रेम में एक पैराग्राफ का प्रतिनिधित्व करता है और इसके पोर्शन तथा पैराग्राफ‑स्तरीय फ़ॉर्मेटिंग तक पहुँच प्रदान करता है।
- Portion पैराग्राफ के भीतर एक टेक्स्ट रन का प्रतिनिधित्व करता है। प्रत्येक पोर्शन का अपना टेक्स्ट और कैरेक्टर‑स्तरीय फ़ॉर्मेटिंग हो सकता है।
इसलिए एक पैराग्राफ कई पोर्शन का उपयोग करके विभिन्न फ़ॉन्ट, रंग, आकार और अन्य फ़ॉर्मेटिंग वाले टेक्स्ट को शामिल कर सकता है।
पैरेग्राफ बनाएं और फ़ॉर्मेट करें
कई पोर्शन के साथ पैराग्राफ बनाएं
निम्नलिखित चरण एक टेक्स्ट फ्रेम बनाते हैं जिसमें तीन पैराग्राफ हैं, प्रत्येक में तीन पोर्शन होते हैं:
- एक Presentation क्लास का उदाहरण बनाएं।
- इंडेक्स के माध्यम से संबंधित स्लाइड तक पहुँचें।
- स्लाइड में एक आयताकार AutoShape जोड़ें।
- shape के TextFrame तक पहुँचें।
- डिफ़ॉल्ट पैराग्राफ का उपयोग करें और टेक्स्ट फ्रेम में दो अतिरिक्त Paragraph ऑब्जेक्ट जोड़ें।
- प्रत्येक पैराग्राफ में तीन पोर्शन रखने के लिए पर्याप्त Portion ऑब्जेक्ट जोड़ें। डिफ़ॉल्ट पैराग्राफ में पहले से ही एक खाली पोर्शन है।
- प्रत्येक पोर्शन का टेक्स्ट सेट करें।
- Portion.getPortionFormat के माध्यम से कैरेक्टर‑स्तरीय फ़ॉर्मेटिंग लागू करें।
- संशोधित प्रस्तुति को सहेजें।
यह Python उदाहरण इन चरणों को लागू करता है:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import FillType, NullableBool, Paragraph, Portion, Presentation, SaveFormat, ShapeType
from java.awt import Color
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 300, 150)
text_frame = shape.getTextFrame()
first_paragraph = text_frame.getParagraphs().get_Item(0)
first_paragraph.getPortions().add(Portion())
first_paragraph.getPortions().add(Portion())
second_paragraph = Paragraph()
second_paragraph.getPortions().add(Portion())
second_paragraph.getPortions().add(Portion())
second_paragraph.getPortions().add(Portion())
text_frame.getParagraphs().add(second_paragraph)
third_paragraph = Paragraph()
third_paragraph.getPortions().add(Portion())
third_paragraph.getPortions().add(Portion())
third_paragraph.getPortions().add(Portion())
text_frame.getParagraphs().add(third_paragraph)
paragraph_count = text_frame.getParagraphs().getCount()
for paragraph_index in range(paragraph_count):
paragraph = text_frame.getParagraphs().get_Item(paragraph_index)
portion_count = paragraph.getPortions().getCount()
for portion_index in range(portion_count):
portion = paragraph.getPortions().get_Item(portion_index)
portion.setText(f"Portion {paragraph_index + 1}.{portion_index + 1}")
if portion_index == 0:
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid)
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.RED)
portion.getPortionFormat().setFontBold(NullableBool.True_)
portion.getPortionFormat().setFontHeight(15)
elif portion_index == 1:
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid)
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE)
portion.getPortionFormat().setFontItalic(NullableBool.True_)
portion.getPortionFormat().setFontHeight(18)
presentation.save("paragraphs_with_portions.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
बुलेटेड और नंबरित सूचियां बनाएं
बुलेटेड या नंबरित सूची बनाएं
बुलेट और नंबरिंग संबंधित आइटम को आसानी से स्कैन करने में मदद करती है। Aspose.Slides में, सूची सेटिंग्स को BulletFormat के माध्यम से परिभाषित किया जाता है।
- एक Presentation क्लास का उदाहरण बनाएं।
- इंडेक्स के माध्यम से संबंधित स्लाइड तक पहुँचें।
- चयनित स्लाइड में एक AutoShape जोड़ें।
- shape के TextFrame तक पहुँचें।
- टेक्स्ट फ्रेम से डिफ़ॉल्ट पैराग्राफ हटाएँ।
- एक प्रतीक बुलेट के लिए एक Paragraph बनाएं।
- BulletFormat.setType को BulletType.Symbol पर सेट करें और बुलेट कैरेक्टर निर्दिष्ट करें।
- पैराग्राफ टेक्स्ट, इंडेंट, बुलेट रंग और बुलेट ऊँचाई सेट करें।
- पैराग्राफ को टेक्स्ट फ्रेम में जोड़ें।
- दूसरा पैराग्राफ बनाएं और BulletFormat.setType को BulletType.Numbered पर सेट करें।
- नंबरित बुलेट शैली को कॉन्फ़िगर करें और पैराग्राफ को टेक्स्ट फ्रेम में जोड़ें।
- प्रस्तुति को सहेजें।
यह Python उदाहरण एक प्रतीक बुलेट और एक नंबरित बुलेट बनाता है:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BulletType, ColorType, NullableBool, NumberedBulletStyle, Paragraph, Presentation, SaveFormat, ShapeType
from java.awt import Color
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 200, 400, 200)
text_frame = shape.getTextFrame()
text_frame.getParagraphs().clear()
symbol_paragraph = Paragraph()
symbol_paragraph.setText("Welcome to Aspose.Slides")
symbol_paragraph.getParagraphFormat().getBullet().setType(BulletType.Symbol)
symbol_paragraph.getParagraphFormat().getBullet().setChar("•")
symbol_paragraph.getParagraphFormat().setIndent(25)
symbol_paragraph.getParagraphFormat().getBullet().getColor().setColorType(ColorType.RGB)
symbol_paragraph.getParagraphFormat().getBullet().getColor().setColor(Color.BLACK)
symbol_paragraph.getParagraphFormat().getBullet().setBulletHardColor(NullableBool.True_)
symbol_paragraph.getParagraphFormat().getBullet().setHeight(100)
text_frame.getParagraphs().add(symbol_paragraph)
numbered_paragraph = Paragraph()
numbered_paragraph.setText("This is a numbered item")
numbered_paragraph.getParagraphFormat().getBullet().setType(BulletType.Numbered)
numbered_paragraph.getParagraphFormat().getBullet().setNumberedBulletStyle(NumberedBulletStyle.BulletCircleNumWDBlackPlain)
numbered_paragraph.getParagraphFormat().setIndent(25)
numbered_paragraph.getParagraphFormat().getBullet().getColor().setColorType(ColorType.RGB)
numbered_paragraph.getParagraphFormat().getBullet().getColor().setColor(Color.BLACK)
numbered_paragraph.getParagraphFormat().getBullet().setBulletHardColor(NullableBool.True_)
numbered_paragraph.getParagraphFormat().getBullet().setHeight(100)
text_frame.getParagraphs().add(numbered_paragraph)
presentation.save("bulleted_and_numbered_list.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
चित्र बुलेट्स का उपयोग करें
चित्र बुलेट्स आपको प्रतीक या नंबर के बजाय एक कस्टम इमेज उपयोग करने की अनुमति देते हैं।
- एक Presentation क्लास का उदाहरण बनाएं।
- इंडेक्स के माध्यम से संबंधित स्लाइड तक पहुँचें।
- एक AutoShape जोड़ें और उसके TextFrame तक पहुँचें।
- टेक्स्ट फ्रेम से डिफ़ॉल्ट पैराग्राफ हटाएँ।
- बुलेट इमेज लोड करें और उसे प्रस्तुति की इमेज कलेक्शन में एक PPImage के रूप में जोड़ें।
- एक Paragraph बनाएं और उसका टेक्स्ट सेट करें।
- BulletFormat.setType को BulletType.Picture पर सेट करें।
- BulletFormat.getPicture के माध्यम से इमेज असाइन करें और बुलेट ऊँचाई सेट करें।
- पैराग्राफ को टेक्स्ट फ्रेम में जोड़ें।
- संशोधित प्रस्तुति को सहेजें।
यह Python उदाहरण एक चित्र बुलेट बनाता है:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BulletType, Images, Paragraph, Presentation, SaveFormat, ShapeType
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
bullet_image = Images.fromFile("bullets.png")
try:
presentation_image = presentation.getImages().addImage(bullet_image)
finally:
bullet_image.dispose()
shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 200, 400, 200)
text_frame = shape.getTextFrame()
text_frame.getParagraphs().clear()
paragraph = Paragraph()
paragraph.setText("Welcome to Aspose.Slides")
paragraph.getParagraphFormat().getBullet().setType(BulletType.Picture)
paragraph.getParagraphFormat().getBullet().getPicture().setImage(presentation_image)
paragraph.getParagraphFormat().getBullet().setHeight(100)
text_frame.getParagraphs().add(paragraph)
presentation.save("picture_bullet.pptx", SaveFormat.Pptx)
presentation.save("picture_bullet.ppt", SaveFormat.Ppt)
finally:
presentation.dispose()
बहु-स्तरीय सूची बनाएं
ParagraphFormat.setDepth को सेट करके पैराग्राफ को सूची के विभिन्न स्तरों पर रखा जा सकता है। शीर्ष स्तर की डैप्थ 0 होती है।
- एक Presentation बनाएं और एक स्लाइड तक पहुँचें।
- एक AutoShape जोड़ें और उसके टेक्स्ट फ्रेम से डिफ़ॉल्ट पैराग्राफ हटाएँ।
- चार पैराग्राफ बनाएं और उनके बुलेट प्रतीकों को कॉन्फ़िगर करें।
- उनके ParagraphFormat.setDepth मानों को क्रमशः
0,1,2और3सेट करें। - पैराग्राफ को टेक्स्ट फ्रेम में जोड़ें और प्रस्तुति को सहेजें।
यह Python उदाहरण चार‑स्तरीय बुलेटेड सूची बनाता है:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BulletType, FillType, Paragraph, Presentation, SaveFormat, ShapeType
from java.awt import Color
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 200, 400, 200)
text_frame = shape.getTextFrame()
text_frame.getParagraphs().clear()
first_paragraph = Paragraph()
first_paragraph.setText("Content")
first_paragraph.getParagraphFormat().getBullet().setType(BulletType.Symbol)
first_paragraph.getParagraphFormat().getBullet().setChar("•")
first_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid)
first_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK)
first_paragraph.getParagraphFormat().setDepth(0)
second_paragraph = Paragraph()
second_paragraph.setText("Second level")
second_paragraph.getParagraphFormat().getBullet().setType(BulletType.Symbol)
second_paragraph.getParagraphFormat().getBullet().setChar('-')
second_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid)
second_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK)
second_paragraph.getParagraphFormat().setDepth(1)
third_paragraph = Paragraph()
third_paragraph.setText("Third level")
third_paragraph.getParagraphFormat().getBullet().setType(BulletType.Symbol)
third_paragraph.getParagraphFormat().getBullet().setChar("•")
third_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid)
third_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK)
third_paragraph.getParagraphFormat().setDepth(2)
fourth_paragraph = Paragraph()
fourth_paragraph.setText("Fourth level")
fourth_paragraph.getParagraphFormat().getBullet().setType(BulletType.Symbol)
fourth_paragraph.getParagraphFormat().getBullet().setChar('-')
fourth_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid)
fourth_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK)
fourth_paragraph.getParagraphFormat().setDepth(3)
text_frame.getParagraphs().add(first_paragraph)
text_frame.getParagraphs().add(second_paragraph)
text_frame.getParagraphs().add(third_paragraph)
text_frame.getParagraphs().add(fourth_paragraph)
presentation.save("multilevel_list.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
कस्टम मानों पर नंबरित सूची आइटम शुरू करें
BulletFormat.setNumberedBulletStartWith का उपयोग करके नंबरित पैराग्राफ के प्रारंभिक नंबर को सेट किया जा सकता है।
- एक Presentation बनाएं और एक AutoShape को स्लाइड में जोड़ें।
- shape के टेक्स्ट फ्रेम से डिफ़ॉल्ट पैराग्राफ हटाएँ।
- तीन नंबरित पैराग्राफ बनाएं।
- प्रत्येक पैराग्राफ के लिए BulletFormat.setNumberedBulletStartWith को क्रमशः
2,3और7पर सेट करें। - पैराग्राफ को टेक्स्ट फ्रेम में जोड़ें और प्रस्तुति को सहेजें।
यह Python उदाहरण प्रत्येक पैराग्राफ को कस्टम शुरुआती नंबर असाइन करता है:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BulletType, Paragraph, Presentation, SaveFormat, ShapeType
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 200, 400, 200)
text_frame = shape.getTextFrame()
text_frame.getParagraphs().clear()
first_paragraph = Paragraph()
first_paragraph.setText("Start at 2")
first_paragraph.getParagraphFormat().getBullet().setType(BulletType.Numbered)
first_paragraph.getParagraphFormat().getBullet().setNumberedBulletStartWith(2)
text_frame.getParagraphs().add(first_paragraph)
second_paragraph = Paragraph()
second_paragraph.setText("Start at 3")
second_paragraph.getParagraphFormat().getBullet().setType(BulletType.Numbered)
second_paragraph.getParagraphFormat().getBullet().setNumberedBulletStartWith(3)
text_frame.getParagraphs().add(second_paragraph)
third_paragraph = Paragraph()
third_paragraph.setText("Start at 7")
third_paragraph.getParagraphFormat().getBullet().setType(BulletType.Numbered)
third_paragraph.getParagraphFormat().getBullet().setNumberedBulletStartWith(7)
text_frame.getParagraphs().add(third_paragraph)
presentation.save("custom_numbered_list.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
पैराग्राफ लेआउट और अंत गुणों को नियंत्रित करें
पहली-लाइन इंडेंट सेट करें
ParagraphFormat.setIndent का उपयोग करके पैराग्राफ की पहली‑लाइन इंडेंट को नियंत्रित किया जाता है। यह मेथड केवल पैराग्राफ के बाएँ मार्जिन के सापेक्ष पहली लाइन को ही स्थानांतरित करता है। सकारात्मक मान पहली लाइन को दाईं दिशा में शिफ्ट करता है, जबकि बाकी लाइनों को पैराग्राफ बॉडी के साथ संरेखित रहता है।
जब आपको पूरे पैराग्राफ को स्थानांतरित करने की आवश्यकता हो तो ParagraphFormat.setMarginLeft का उपयोग करें। जब आपको केवल पहली लाइन को स्थानांतरित करना हो तो ParagraphFormat.setIndent का उपयोग करें।
निचे दिया गया उदाहरण कई पैराग्राफ बनाता है और विभिन्न ParagraphFormat.setIndent मानों को लागू करके दर्शाता है कि पहली‑लाइन इंडेंट पैराग्राफ लेआउट को कैसे प्रभावित करता है।
- एक Presentation क्लास का उदाहरण बनाएं।
- लक्ष्य स्लाइड तक पहुँचें।
- स्लाइड में एक आयताकार AutoShape जोड़ें।
- shape के TextFrame तक पहुँचें और डिफ़ॉल्ट पैराग्राफ हटाएँ।
- कई पैराग्राफ बनाएं और उनके लिए अलग‑अलग ParagraphFormat.setIndent मान सेट करें।
- पैराग्राफ को टेक्स्ट फ्रेम में जोड़ें।
- संशोधित प्रस्तुति को सहेजें।
यह कोड पैराग्राफ इंडेंट सेट करने का तरीका दिखाता है:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import FillType, Paragraph, Presentation, SaveFormat, ShapeType, TextAutofitType
from java.awt import Color
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 420, 220)
shape.getFillFormat().setFillType(FillType.NoFill)
shape.getLineFormat().getFillFormat().setFillType(FillType.Solid)
shape.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY)
text_frame = shape.getTextFrame()
text_frame.getTextFrameFormat().setAutofitType(TextAutofitType.Shape)
text_frame.getParagraphs().clear()
first_paragraph = Paragraph()
first_paragraph.setText("No first-line indent. Wrapped lines start at the same position as the first line.")
first_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid)
first_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK)
first_paragraph.getParagraphFormat().setMarginLeft(20.0)
first_paragraph.getParagraphFormat().setIndent(0.0)
second_paragraph = Paragraph()
second_paragraph.setText("First-line indent of 20 points. The first line moves to the right, while wrapped lines remain aligned to the paragraph body.")
second_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid)
second_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK)
second_paragraph.getParagraphFormat().setMarginLeft(20.0)
second_paragraph.getParagraphFormat().setIndent(20.0)
third_paragraph = Paragraph()
third_paragraph.setText("First-line indent of 40 points. This paragraph shows a larger first-line offset to make the effect easier to see.")
third_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid)
third_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK)
third_paragraph.getParagraphFormat().setMarginLeft(20.0)
third_paragraph.getParagraphFormat().setIndent(40.0)
text_frame.getParagraphs().add(first_paragraph)
text_frame.getParagraphs().add(second_paragraph)
text_frame.getParagraphs().add(third_paragraph)
presentation.save("paragraph_indent.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
परिणाम:

हैंगिंग इंडेंट सेट करें
हैंगिंग इंडेंट वह पैराग्राफ लेआउट है जिसमें पहली लाइन बाकी लाइनों की बाएँ ओर शुरू होती है। Aspose.Slides में यह प्रभाव ParagraphFormat.setIndent के द्वारा हासिल किया जाता है। पैराग्राफ बॉडी के सापेक्ष पहली लाइन को बाएँ ले जाने के लिये नकारात्मक मान पास करें।
व्यावहारिक रूप से, ParagraphFormat.setMarginLeft पैराग्राफ बॉडी की बाएँ स्थिति निर्धारित करता है, और ParagraphFormat.setIndent पहली लाइन की स्थिति को उस मार्जिन के सापेक्ष तय करता है। हैंगिंग इंडेंट बनाने के लिये, प्रत्येक पैराग्राफ के लिए ParagraphFormat.setMarginLeft को सकारात्मक मान और ParagraphFormat.setIndent को नकारात्मक मान पास करें।
यह फ़ॉर्मेटिंग बाइबिलियोग्राफ़ी, रेफ़रेंसेज़, शब्दकोश प्रविष्टियों आदि में उपयोगी है जहाँ रैप्ड लाइनों को पैराग्राफ बॉडी के नीचे संरेखित होना चाहिए न कि पहली लाइन के पहले कैरेक्टर के नीचे।
- एक Presentation क्लास का उदाहरण बनाएं।
- लक्ष्य स्लाइड तक पहुँचें।
- स्लाइड में एक आयताकार AutoShape जोड़ें।
- shape के TextFrame तक पहुँचें और डिफ़ॉल्ट पैराग्राफ हटाएँ।
- पैराग्राफ बनाएँ और प्रत्येक के लिए ParagraphFormat.setMarginLeft को सकारात्मक मान पास करें।
- हैंगिंग इंडेंट प्रभाव बनाने के लिये ParagraphFormat.setIndent को नकारात्मक मान पास करें।
- पैराग्राफ को टेक्स्ट फ्रेम में जोड़ें।
- संशोधित प्रस्तुति को सहेजें।
यह कोड पैराग्राफ के लिए हैंगिंग इंडेंट सेट करने का तरीका दिखाता है:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import FillType, Paragraph, Presentation, SaveFormat, ShapeType, TextAutofitType
from java.awt import Color
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 420, 220)
shape.getFillFormat().setFillType(FillType.NoFill)
shape.getLineFormat().getFillFormat().setFillType(FillType.Solid)
shape.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY)
text_frame = shape.getTextFrame()
text_frame.getTextFrameFormat().setAutofitType(TextAutofitType.Shape)
text_frame.getParagraphs().clear()
first_paragraph = Paragraph()
first_paragraph.setText("A hanging indent is created by combining a positive left margin with a negative indent. The first line starts to the left, while wrapped lines align with the paragraph body.")
first_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid)
first_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK)
first_paragraph.getParagraphFormat().setMarginLeft(40.0)
first_paragraph.getParagraphFormat().setIndent(-20.0)
second_paragraph = Paragraph()
second_paragraph.setText("This second example uses a deeper hanging indent so the difference between the first line and the wrapped lines is easier to compare.")
second_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid)
second_paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK)
second_paragraph.getParagraphFormat().setMarginLeft(60.0)
second_paragraph.getParagraphFormat().setIndent(-30.0)
text_frame.getParagraphs().add(first_paragraph)
text_frame.getParagraphs().add(second_paragraph)
presentation.save("hanging_indent.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
परिणाम:

अंत पैराग्राफ रन गुण सेट करें
Paragraph.setEndParagraphPortionFormat पैराग्राफ अंत मान के फ़ॉर्मेट को नियंत्रित करता है। नीचे दिया गया उदाहरण दूसरे पैराग्राफ के अंत मान को फ़ॉन्ट साइज और लैटिन फ़ॉन्ट असाइन करता है:
- एक Presentation लोड करें और एक स्लाइड तक पहुँचें।
- एक AutoShape जोड़ें और उसका डिफ़ॉल्ट पैराग्राफ साफ़ करें।
- दो पैराग्राफ बनाएं और उनसे टेक्स्ट पोर्शन जोड़ें।
- दूसरे पैराग्राफ के अंत मान के लिये एक PortionFormat बनाएं।
- BasePortionFormat.setFontHeight और BasePortionFormat.setLatinFont सेट करें।
- Paragraph.setEndParagraphPortionFormat के साथ फ़ॉर्मेट असाइन करें और प्रस्तुति को सहेजें।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import FontData, Paragraph, Portion, PortionFormat, Presentation, SaveFormat, ShapeType
presentation = Presentation("Test.pptx")
try:
slide = presentation.getSlides().get_Item(0)
shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 10, 200, 250)
text_frame = shape.getTextFrame()
text_frame.getParagraphs().clear()
first_paragraph = Paragraph()
first_portion = Portion("Sample text")
first_paragraph.getPortions().add(first_portion)
second_paragraph = Paragraph()
second_portion = Portion("Sample text 2")
second_paragraph.getPortions().add(second_portion)
end_paragraph_format = PortionFormat()
end_paragraph_format.setFontHeight(48)
latin_font = FontData("Times New Roman")
end_paragraph_format.setLatinFont(latin_font)
second_paragraph.setEndParagraphPortionFormat(end_paragraph_format)
text_frame.getParagraphs().add(first_paragraph)
text_frame.getParagraphs().add(second_paragraph)
presentation.save("end_paragraph_format.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
रेंडर की गई लाइनों की गिनती करें
रैपिंग और लाइन‑एंड पंक्चुएशन को प्रभावित करने वाले पैराग्राफ नियमों के लिये देखें Control Line Breaking और Control Hanging Punctuation।
Paragraph.getLinesCount का उपयोग करके टेक्स्ट लेआउट के बाद किसी पैराग्राफ द्वारा कब्जा की गई लाइनों की संख्या गिनी जा सकती है, जिसमें ऑटोमैटिक रैपिंग भी शामिल है। यह तब उपयोगी होता है जब प्रस्तुति टेम्पलेट में टेक्स्ट की लंबाई और लेआउट जांचना हो।
एक पैराग्राफ TextFrame.getParagraphs में एक आइटम है, और यह कई रेंडर की गई लाइनों को कवर कर सकता है। पैराग्राफ के भीतर स्पष्ट लाइन‑ब्रेक नया लाइन बनाता है बिना नया पैराग्राफ बनाए। ऑटोमैटिक रैपिंग उपलब्ध चौड़ाई के आधार पर लाइनों का निर्माण करता है, बिना टेक्स्ट में स्पष्ट लाइन‑ब्रेक डाले। इसलिए पैराग्राफ या लाइन‑ब्रेक कैरेक्टर की गिनती रेंडर की गई लाइन‑काउंट नहीं देती।
निचे दिया गया उदाहरण एक टेक्स्ट शेप बनाता है, उसकी लाइनों की गिनती करता है, शेप को संकीर्ण करता है, और फिर टेक्स्ट को छोटे स्ट्रिंग से बदलता है। रैपिंग सक्रिय है और ऑटो‑फ़िट निष्क्रिय है ताकि शेप की चौड़ाई रैपिंग को नियंत्रित करे बिना टेक्स्ट को स्वतः छोटा किए या शेप को रीसाइज़ किए। शेप के आयाम पॉइंट में होते हैं। अंत में उदाहरण एक और पैराग्राफ जोड़ता है और टेक्स्ट फ्रेम में सभी लाइन‑काउंट का योग करता है।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import NullableBool, Paragraph, Presentation, ShapeType, TextAutofitType
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 400, 200)
text_frame = shape.getTextFrame()
text_frame.getTextFrameFormat().setWrapText(NullableBool.True_)
text_frame.getTextFrameFormat().setAutofitType(TextAutofitType.None_)
paragraph = text_frame.getParagraphs().get_Item(0)
paragraph.getParagraphFormat().getDefaultPortionFormat().setFontHeight(20)
paragraph.setText("This text demonstrates how automatic wrapping changes the number of rendered lines.")
print("Original width:", paragraph.getLinesCount())
shape.setWidth(150)
print("Narrower shape:", paragraph.getLinesCount())
paragraph.setText("Short text.")
print("Shorter text:", paragraph.getLinesCount())
second_paragraph = Paragraph()
second_paragraph.setText("Another paragraph.")
second_paragraph.getParagraphFormat().getDefaultPortionFormat().setFontHeight(20)
text_frame.getParagraphs().add(second_paragraph)
total_line_count = 0
for current_paragraph in text_frame.getParagraphs():
total_line_count += current_paragraph.getLinesCount()
print("Total lines in the text frame:", total_line_count)
finally:
presentation.dispose()
इन टेक्स्ट और आयामों के साथ, शेप को संकीर्ण करने से लाइन‑काउंट बढ़ेगा, जबकि छोटे स्ट्रिंग से बदलने से घटेगा। सटीक गणना फ़ॉन्ट उपलब्धता, फ़ॉन्ट साइज, मार्जिन, इंडेंटेशन, रैपिंग और ऑटो‑फ़िट सेटिंग्स के आधार पर बदल सकती है। टेम्पलेट की जांच करते समय लक्षित वातावरण के लिए उपयोग किए जाने वाले फ़ॉन्ट और लेआउट सेटिंग्स का उपयोग करें।
केवल लाइन‑काउंट यह निर्धारित नहीं करता कि टेक्स्ट कंटेनर से बाहर निकल रहा है या नहीं। उपलब्ध ऊँचाई, लाइन‑ऊँचाइयाँ, पैराग्राफ और लाइन स्पेसिंग, तथा ऑटो‑फ़िट व्यवहार भी मायने रखते हैं; यहाँ तक कि एक ही लाइन भी जब रैपिंग निष्क्रिय हो तो उपलब्ध चौड़ाई से अधिक हो सकती है।
पैराग्राफ सामग्री आयात और निर्यात करें
HTML टेक्स्ट को पैराग्राफ में आयात करें
ParagraphCollection.addFromHtml का उपयोग करके HTML मार्कअप को टेक्स्ट फ्रेम में पैराग्राफ और पोर्शन में बदला जा सकता है।
- एक Presentation क्लास का उदाहरण बनाएं।
- एक स्लाइड तक पहुँचें और एक AutoShape जोड़ें।
- shape के TextFrame तक पहुँचें और उसका डिफ़ॉल्ट पैराग्राफ साफ़ करें।
- स्रोत HTML फ़ाइल पढ़ें।
- HTML स्ट्रिंग को ParagraphCollection.addFromHtml को पास करें।
- संशोधित प्रस्तुति को सहेजें।
यह Python उदाहरण HTML को टेक्स्ट फ्रेम में आयात करता है:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import FillType, Presentation, SaveFormat, ShapeType
from pathlib import Path
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
shape_width = presentation.getSlideSize().getSize().getWidth() - 20
shape_height = presentation.getSlideSize().getSize().getHeight() - 20
shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 10, shape_width, shape_height)
shape.getFillFormat().setFillType(FillType.NoFill)
shape.getTextFrame().getParagraphs().clear()
try:
html = Path("file.html").read_text(encoding="utf-8")
shape.getTextFrame().getParagraphs().addFromHtml(html)
presentation.save("html_text.pptx", SaveFormat.Pptx)
except OSError as exception:
print("The HTML file could not be read: " + str(exception))
finally:
presentation.dispose()
पैराग्राफ टेक्स्ट को HTML में निर्यात करें
ParagraphCollection.exportToHtml का उपयोग करके चयनित पैराग्राफ रेंज को HTML के रूप में निर्यात किया जा सकता है।
- एक Presentation का उदाहरण बनाएं और वांछित प्रस्तुति लोड करें।
- स्लाइड तक पहुँचे और उस AutoShape को खोजें जिसमें टेक्स्ट है।
- shape के TextFrame तक पहुँचें।
- प्रारम्भिक पैराग्राफ इंडेक्स और निर्यात करने वाले पैराग्राफों की संख्या के साथ ParagraphCollection.exportToHtml को कॉल करें।
- प्राप्त HTML स्ट्रिंग को फ़ाइल में लिखें।
यह Python उदाहरण पहले टेक्स्ट शेप के सभी पैराग्राफ को निर्यात करता है:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import AutoShape, Presentation
from pathlib import Path
presentation = Presentation("ExportingHTMLText.pptx")
try:
shape = presentation.getSlides().get_Item(0).getShapes().get_Item(0)
if isinstance(shape, AutoShape):
text_shape = shape
text_frame = text_shape.getTextFrame()
if text_frame is not None:
paragraphs = text_frame.getParagraphs()
html = paragraphs.exportToHtml(0, paragraphs.getCount(), None)
try:
Path("paragraphs.html").write_text(str(html), encoding="utf-8")
except OSError as exception:
print("The HTML file could not be written: " + str(exception))
else:
print("The first shape does not contain a text frame.")
else:
print("The first shape is not a text shape.")
finally:
presentation.dispose()
पैराग्राफ को छवि के रूप में रेंडर करें
Paragraph.getImage व्यक्तिगत पैराग्राफ को सीधे रेंडर करता है और एक इमेज ऑब्जेक्ट लौटाता है। save मेथड से परिणाम को फ़ाइल या स्ट्रिम में सहेजा जा सकता है। आपको शेप को रेंडर करने या बिटमैप को मैन्युअल रूप से क्रॉप करने की आवश्यकता नहीं है।
यदि पैराग्राफ को पैरेंट कलेक्शन में नहीं पाया जाता, या वैध रेंडर बाउंड नहीं होते, या रेंडर नहीं किया जा सकता, तो Paragraph.getImage None लौटा सकता है। सहेजने से पहले परिणाम जांचें और उपयोग बाद इमेज को डिस्पोज़ करें।
डिफ़ॉल्ट स्केल पर पैराग्राफ रेंडर करें
मान लीजिए हमारे पास sample.pptx नाम की प्रस्तुति फ़ाइल है जिसमें एक स्लाइड है, और पहला शेप एक टेक्स्ट बॉक्स है जिसमें तीन पैराग्राफ हैं।

निचे दिया गया उदाहरण दूसरे पैराग्राफ को सामान्य टेक्स्ट शेप में डिफ़ॉल्ट स्केल पर रेंडर करता है और PNG फ़ॉर्मेट में लौटाई गई इमेज को सहेजता है। finally ब्लॉक इमेज को सही ढंग से डिस्पोज़ करने को सुनिश्चित करता है।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import AutoShape, ImageFormat, Presentation
presentation = Presentation("sample.pptx")
try:
shape = presentation.getSlides().get_Item(0).getShapes().get_Item(0)
if isinstance(shape, AutoShape):
text_shape = shape
text_frame = text_shape.getTextFrame()
if text_frame is not None and text_frame.getParagraphs().getCount() > 1:
paragraph = text_frame.getParagraphs().get_Item(1)
paragraph_image = paragraph.getImage()
if paragraph_image is not None:
try:
paragraph_image.save("paragraph.png", ImageFormat.Png)
finally:
paragraph_image.dispose()
else:
print("The paragraph could not be rendered.")
else:
print("The expected paragraph was not found.")
else:
print("The first shape is not a text shape.")
finally:
presentation.dispose()
परिणाम:

टेबल सेल में स्केलिंग के साथ पैराग्राफ रेंडर करें
Paragraph.getImage के उस ओवरलोड का उपयोग करें जो scale_x और scale_y पैरामीटर्स स्वीकार करता है ताकि क्षैतिज और लंबवत स्केल फैक्टर सेट किए जा सकें। निचे दिया गया उदाहरण एक टेबल बनाता है, पहले सेल में पैराग्राफ को डिफ़ॉल्ट चौड़ाई और ऊँचाई से दोगुना स्केल करता है, और परिणाम को PNG इमेज के रूप में सहेजता है।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ImageFormat, Presentation
scale_x = 2.0
scale_y = 2.0
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
table = slide.getShapes().addTable(50, 50, [300.0], [80.0])
paragraph = table.get_Item(0, 0).getTextFrame().getParagraphs().get_Item(0)
paragraph.setText("Text in a table cell")
paragraph_image = paragraph.getImage(scale_x, scale_y)
if paragraph_image is not None:
try:
paragraph_image.save("table_paragraph.png", ImageFormat.Png)
finally:
paragraph_image.dispose()
else:
print("The paragraph could not be rendered.")
finally:
presentation.dispose()
1 का स्केल फैक्टर अक्ष को उसकी डिफ़ॉल्ट पिक्सेल साइज पर रखता है। उदाहरण के लिये, दोनों फैक्टर के लिये 2 सेट करने से इमेज की चौड़ाई और ऊँचाई लगभग डिफ़ॉल्ट आयामों का दो गुना हो जाती है, जिससे चार गुना पिक्सेल बनते हैं। बड़े फैक्टर ज़ूम या हाई‑रिज़ॉल्यूशन आउटपुट के लिये टेक्स्ट को तेज़ बनाते हैं, पर मेमोरी उपयोग और फ़ाइल साइज बढ़ाते हैं। 1 से नीचे के फैक्टर छोटे इमेज बनाते हैं जिसमें कम विवरण होता है। पैराग्राफ का एस्पेक्ट रेशियो बरकरार रखने के लिये समान फैक्टर उपयोग करें; अलग‑अलग क्षैतिज और लंबवत फैक्टर आउटपुट को स्वतंत्र रूप से स्ट्रेच करेंगे।
पूरे शेप को Shape.getImage से रेंडर करना उपयोगी रहता है जब आउटपुट में शेप का फ़िल, बॉर्डर या अन्य विज़ुअल कॉन्टेक्ट शामिल करना हो। केवल पैराग्राफ‑की छवि के लिये, Paragraph.getImage का उपयोग करें।
अक्सर पूछे जाने वाले प्रश्न
क्या मैं टेक्स्ट फ्रेम के भीतर लाइन रैपिंग को पूरी तरह अक्षम कर सकता हूँ?
हां। TextFrameFormat.setWrapText को सेट करके रैपिंग अक्षम की जा सकती है ताकि लाइनों को टेक्स्ट फ्रेम के किनारों पर तोड़ा न जाए।
मैं किसी विशिष्ट पैराग्राफ की ऑन‑स्लाइड बाउंडिस कैसे प्राप्त करूँ?
Paragraph.getRect का उपयोग करके पैराग्राफ का बाउंडिंग रेक्टैंगल प्राप्त किया जा सकता है। Portion.getRect एक व्यक्तिगत पोर्शन की बाउंड्स देता है।
पैराग्राफ एलाइनमेंट (बाएँ, दाएँ, केंद्र या जस्टिफ़ाई) कहाँ नियंत्रित होता है?
ParagraphFormat.setAlignment पैराग्राफ‑स्तर की सेटिंग है और यह पूरे पैराग्राफ पर लागू होती है, चाहे व्यक्तिगत पोर्शन का फ़ॉर्मेट कुछ भी हो।
विभिन्न फ़ॉन्ट साइज वाले पोर्शन को प्रत्येक लाइन में वेरटिकली एलाइन करने के लिये देखें Align Fonts Within a Line।
क्या मैं पैराग्राफ के किसी भाग के लिये प्रूफ़िंग भाषा सेट कर सकता हूँ?
हां। प्रत्येक पोर्शन के लिये BasePortionFormat.setLanguageId सेट करके एक ही पैराग्राफ में विभिन्न भाषाओं का टेक्स्ट शामिल किया जा सकता है।