पाइथन में PowerPoint टेक्स्ट पैराग्राफ प्रबंधित करें

Contents
[ ]

परिचय

Aspose.Slides for Python via .NET पाठ को टेक्स्ट फ्रेम, पैराग्राफ और पोर्शन के पदानुक्रम के रूप में प्रतिनिधित्व करता है:

  • TextFrame आकृति में पाठ कंटेनर का प्रतिनिधित्व करता है और इसके पैराग्राफ संग्रह तक पहुँच प्रदान करता है।
  • Paragraph एक टेक्स्ट फ्रेम में एक पैराग्राफ का प्रतिनिधित्व करता है और इसके पोर्शन और पैराग्राफ‑स्तर फ़ॉर्मेटिंग तक पहुँच प्रदान करता है।
  • Portion पैराग्राफ के भीतर एक टेक्स्ट रन का प्रतिनिधित्व करता है। प्रत्येक पोर्शन का अपना टेक्स्ट और कैरेक्टर‑स्तर फ़ॉर्मेटिंग हो सकता है।

इसलिए एक पैराग्राफ कई पोर्शन का उपयोग करके विभिन्न फ़ॉन्ट, रंग, आकार और अन्य फ़ॉर्मेटिंग वाले पाठ को समाहित कर सकता है।

पैराग्राफ बनाएँ और फ़ॉर्मेट करें

कई पोर्शन वाले पैराग्राफ बनाएँ

निम्नलिखित चरण तीन पैराग्राफ के साथ एक टेक्स्ट फ्रेम बनाते हैं, प्रत्येक में तीन पोर्शन होते हैं:

  1. Presentation क्लास का एक उदाहरण बनाएँ।
  2. इंडेक्स के माध्यम से संबंधित स्लाइड तक पहुँचें।
  3. स्लाइड में एक आयताकार AutoShape जोड़ें।
  4. शैप के TextFrame तक पहुँचें।
  5. डिफ़ॉल्ट पैराग्राफ का उपयोग करके दो अतिरिक्त Paragraph ऑब्जेक्ट टेक्स्ट फ्रेम में जोड़ें।
  6. प्रत्येक पैराग्राफ के लिए पर्याप्त Portion ऑब्जेक्ट जोड़ें ताकि तीन पोर्शन हो सकें। डिफ़ॉल्ट पैराग्राफ में पहले से ही एक खाली पोर्शन होता है।
  7. प्रत्येक पोर्शन का टेक्स्ट सेट करें।
  8. Portion.portion_format के माध्यम से कैरेक्टर‑स्तर फ़ॉर्मेटिंग लागू करें।
  9. संशोधित प्रस्तुति सहेजें।

यह Python उदाहरण इन चरणों को लागू करता है:

import aspose.pydrawing as draw
import aspose.slides as slides

with slides.Presentation() as presentation:
    slide = presentation.slides[0]
    shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 150, 300, 150)
    text_frame = shape.text_frame

    first_paragraph = text_frame.paragraphs[0]
    first_paragraph.portions.add(slides.Portion())
    first_paragraph.portions.add(slides.Portion())

    second_paragraph = slides.Paragraph()
    second_paragraph.portions.add(slides.Portion())
    second_paragraph.portions.add(slides.Portion())
    second_paragraph.portions.add(slides.Portion())
    text_frame.paragraphs.add(second_paragraph)

    third_paragraph = slides.Paragraph()
    third_paragraph.portions.add(slides.Portion())
    third_paragraph.portions.add(slides.Portion())
    third_paragraph.portions.add(slides.Portion())
    text_frame.paragraphs.add(third_paragraph)

    for paragraph_index in range(text_frame.paragraphs.count):
        paragraph = text_frame.paragraphs[paragraph_index]
        for portion_index in range(paragraph.portions.count):
            portion = paragraph.portions[portion_index]
            portion.text = f"Portion {paragraph_index + 1}.{portion_index + 1}"

            if portion_index == 0:
                portion.portion_format.fill_format.fill_type = slides.FillType.SOLID
                portion.portion_format.fill_format.solid_fill_color.color = draw.Color.red
                portion.portion_format.font_bold = slides.NullableBool.TRUE
                portion.portion_format.font_height = 15
            elif portion_index == 1:
                portion.portion_format.fill_format.fill_type = slides.FillType.SOLID
                portion.portion_format.fill_format.solid_fill_color.color = draw.Color.blue
                portion.portion_format.font_italic = slides.NullableBool.TRUE
                portion.portion_format.font_height = 18

    presentation.save("paragraphs_with_portions.pptx", slides.export.SaveFormat.PPTX)

बुलेटेड और नंबर्ड सूचियाँ बनाएँ

बुलेटेड या नंबर्ड सूची बनाएँ

बुलेट और नंबरिंग संबंधित आइटम को स्कैन करना आसान बनाते हैं। Aspose.Slides में, सूची सेटिंग्स BulletFormat के माध्यम से परिभाषित की जाती हैं।

  1. Presentation क्लास का एक उदाहरण बनाएँ।
  2. इंडेक्स के माध्यम से संबंधित स्लाइड तक पहुँचें।
  3. चयनित स्लाइड में एक AutoShape जोड़ें।
  4. शैप के TextFrame तक पहुँचें।
  5. टेक्स्ट फ्रेम से डिफ़ॉल्ट पैराग्राफ हटाएँ।
  6. एक सिम्बॉल बुलेट के लिए एक Paragraph बनाएँ।
  7. BulletFormat.type को BulletType.SYMBOL सेट करें और बुलेट कैरेक्टर निर्दिष्ट करें।
  8. पैराग्राफ का टेक्स्ट, इंडेंट, बुलेट रंग और बुलेट ऊँचाई सेट करें।
  9. पैराग्राफ को टेक्स्ट फ्रेम में जोड़ें।
  10. दूसरा पैराग्राफ बनाएँ और BulletFormat.type को BulletType.NUMBERED सेट करें।
  11. नंबर्ड बुलेट शैली को कॉन्फ़िगर करें और पैराग्राफ को टेक्स्ट फ्रेम में जोड़ें।
  12. प्रस्तुति सहेजें।

यह Python उदाहरण सिम्बॉल बुलेट और नंबर्ड बुलेट बनाता है:

import aspose.pydrawing as draw
import aspose.slides as slides

with slides.Presentation() as presentation:
    slide = presentation.slides[0]
    shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 200, 200, 400, 200)
    text_frame = shape.text_frame
    text_frame.paragraphs.clear()

    symbol_paragraph = slides.Paragraph()
    symbol_paragraph.text = "Welcome to Aspose.Slides"
    symbol_paragraph.paragraph_format.bullet.type = slides.BulletType.SYMBOL
    symbol_paragraph.paragraph_format.bullet.char = chr(0x2022)
    symbol_paragraph.paragraph_format.indent = 25
    symbol_paragraph.paragraph_format.bullet.color.color_type = slides.ColorType.RGB
    symbol_paragraph.paragraph_format.bullet.color.color = draw.Color.black
    symbol_paragraph.paragraph_format.bullet.is_bullet_hard_color = slides.NullableBool.TRUE
    symbol_paragraph.paragraph_format.bullet.height = 100
    text_frame.paragraphs.add(symbol_paragraph)

    numbered_paragraph = slides.Paragraph()
    numbered_paragraph.text = "This is a numbered item"
    numbered_paragraph.paragraph_format.bullet.type = slides.BulletType.NUMBERED
    numbered_paragraph.paragraph_format.bullet.numbered_bullet_style = slides.NumberedBulletStyle.BULLET_CIRCLE_NUM_WD_BLACK_PLAIN
    numbered_paragraph.paragraph_format.indent = 25
    numbered_paragraph.paragraph_format.bullet.color.color_type = slides.ColorType.RGB
    numbered_paragraph.paragraph_format.bullet.color.color = draw.Color.black
    numbered_paragraph.paragraph_format.bullet.is_bullet_hard_color = slides.NullableBool.TRUE
    numbered_paragraph.paragraph_format.bullet.height = 100
    text_frame.paragraphs.add(numbered_paragraph)

    presentation.save("bulleted_and_numbered_list.pptx", slides.export.SaveFormat.PPTX)

पिक्चर बुलेट्स उपयोग करें

पिक्चर बुलेट आपको सिम्बॉल या संख्या के बजाय एक कस्टम इमेज उपयोग करने की अनुमति देता है।

  1. Presentation क्लास का एक उदाहरण बनाएँ।
  2. इंडेक्स के माध्यम से संबंधित स्लाइड तक पहुँचें।
  3. एक AutoShape जोड़ें और उसके TextFrame तक पहुँचें।
  4. टेक्स्ट फ्रेम से डिफ़ॉल्ट पैराग्राफ हटाएँ।
  5. बुलेट इमेज लोड करें और उसे प्रस्तुति की इमेज कलेक्शन में एक PPImage के रूप में जोड़ें।
  6. एक Paragraph बनाएँ और उसका टेक्स्ट सेट करें।
  7. BulletFormat.type को BulletType.PICTURE सेट करें।
  8. BulletFormat.picture के माध्यम से इमेज असाइन करें और बुलेट ऊँचाई सेट करें।
  9. पैराग्राफ को टेक्स्ट फ्रेम में जोड़ें।
  10. संशोधित प्रस्तुति सहेजें।

यह Python उदाहरण पिक्चर बुलेट बनाता है:

import aspose.slides as slides

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    with slides.Images.from_file("bullets.png") as bullet_image:
        presentation_image = presentation.images.add_image(bullet_image)

    shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 200, 200, 400, 200)
    text_frame = shape.text_frame
    text_frame.paragraphs.clear()

    paragraph = slides.Paragraph()
    paragraph.text = "Welcome to Aspose.Slides"
    paragraph.paragraph_format.bullet.type = slides.BulletType.PICTURE
    paragraph.paragraph_format.bullet.picture.image = presentation_image
    paragraph.paragraph_format.bullet.height = 100
    text_frame.paragraphs.add(paragraph)

    presentation.save("picture_bullet.pptx", slides.export.SaveFormat.PPTX)
    presentation.save("picture_bullet.ppt", slides.export.SaveFormat.PPT)

मल्टीलेवल सूची बनाएँ

ParagraphFormat.depth सेट करके पैराग्राफ को सूची के विभिन्न स्तरों पर रखा जाता है। शीर्ष स्तर की depth 0 होती है।

  1. एक Presentation बनाएँ और एक स्लाइड तक पहुँचें।
  2. एक AutoShape जोड़ें और उसके टेक्स्ट फ्रेम से डिफ़ॉल्ट पैराग्राफ को साफ़ करें।
  3. चार पैराग्राफ बनाएँ और उनके बुलेट सिम्बॉल कॉन्फ़िगर करें।
  4. उनके ParagraphFormat.depth मानों को क्रमशः 0, 1, 2, और 3 सेट करें।
  5. पैराग्राफ को टेक्स्ट फ्रेम में जोड़ें और प्रस्तुति सहेजें।

यह Python उदाहरण चार‑स्तर की बुलेटेड सूची बनाता है:

import aspose.pydrawing as draw
import aspose.slides as slides

with slides.Presentation() as presentation:
    slide = presentation.slides[0]
    shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 200, 200, 400, 200)
    text_frame = shape.text_frame
    text_frame.paragraphs.clear()

    first_paragraph = slides.Paragraph()
    first_paragraph.text = "Content"
    first_paragraph.paragraph_format.bullet.type = slides.BulletType.SYMBOL
    first_paragraph.paragraph_format.bullet.char = chr(0x2022)
    first_paragraph.paragraph_format.default_portion_format.fill_format.fill_type = slides.FillType.SOLID
    first_paragraph.paragraph_format.default_portion_format.fill_format.solid_fill_color.color = draw.Color.black
    first_paragraph.paragraph_format.depth = 0

    second_paragraph = slides.Paragraph()
    second_paragraph.text = "Second level"
    second_paragraph.paragraph_format.bullet.type = slides.BulletType.SYMBOL
    second_paragraph.paragraph_format.bullet.char = "-"
    second_paragraph.paragraph_format.default_portion_format.fill_format.fill_type = slides.FillType.SOLID
    second_paragraph.paragraph_format.default_portion_format.fill_format.solid_fill_color.color = draw.Color.black
    second_paragraph.paragraph_format.depth = 1

    third_paragraph = slides.Paragraph()
    third_paragraph.text = "Third level"
    third_paragraph.paragraph_format.bullet.type = slides.BulletType.SYMBOL
    third_paragraph.paragraph_format.bullet.char = chr(0x2022)
    third_paragraph.paragraph_format.default_portion_format.fill_format.fill_type = slides.FillType.SOLID
    third_paragraph.paragraph_format.default_portion_format.fill_format.solid_fill_color.color = draw.Color.black
    third_paragraph.paragraph_format.depth = 2

    fourth_paragraph = slides.Paragraph()
    fourth_paragraph.text = "Fourth level"
    fourth_paragraph.paragraph_format.bullet.type = slides.BulletType.SYMBOL
    fourth_paragraph.paragraph_format.bullet.char = "-"
    fourth_paragraph.paragraph_format.default_portion_format.fill_format.fill_type = slides.FillType.SOLID
    fourth_paragraph.paragraph_format.default_portion_format.fill_format.solid_fill_color.color = draw.Color.black
    fourth_paragraph.paragraph_format.depth = 3

    text_frame.paragraphs.add(first_paragraph)
    text_frame.paragraphs.add(second_paragraph)
    text_frame.paragraphs.add(third_paragraph)
    text_frame.paragraphs.add(fourth_paragraph)

    presentation.save("multilevel_list.pptx", slides.export.SaveFormat.PPTX)

नंबर्ड सूची आइटम्स को कस्टम मानों से शुरू करें

BulletFormat.numbered_bullet_start_with का उपयोग करके नंबर्ड पैराग्राफ के लिए प्रारंभिक संख्या सेट करें।

  1. एक Presentation बनाएँ और एक AutoShape स्लाइड में जोड़ें।
  2. शैप के टेक्स्ट फ्रेम से डिफ़ॉल्ट पैराग्राफ साफ़ करें।
  3. तीन नंबर्ड पैराग्राफ बनाएँ।
  4. प्रत्येक पैराग्राफ के लिए BulletFormat.numbered_bullet_start_with को क्रमशः 2, 3, और 7 सेट करें।
  5. पैराग्राफ को टेक्स्ट फ्रेम में जोड़ें और प्रस्तुति सहेजें।

यह Python उदाहरण प्रत्येक पैराग्राफ के लिए कस्टम प्रारंभिक संख्या असाइन करता है:

import aspose.slides as slides

with slides.Presentation() as presentation:
    slide = presentation.slides[0]
    shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 200, 200, 400, 200)
    text_frame = shape.text_frame
    text_frame.paragraphs.clear()

    first_paragraph = slides.Paragraph()
    first_paragraph.text = "Start at 2"
    first_paragraph.paragraph_format.bullet.type = slides.BulletType.NUMBERED
    first_paragraph.paragraph_format.bullet.numbered_bullet_start_with = 2
    text_frame.paragraphs.add(first_paragraph)

    second_paragraph = slides.Paragraph()
    second_paragraph.text = "Start at 3"
    second_paragraph.paragraph_format.bullet.type = slides.BulletType.NUMBERED
    second_paragraph.paragraph_format.bullet.numbered_bullet_start_with = 3
    text_frame.paragraphs.add(second_paragraph)

    third_paragraph = slides.Paragraph()
    third_paragraph.text = "Start at 7"
    third_paragraph.paragraph_format.bullet.type = slides.BulletType.NUMBERED
    third_paragraph.paragraph_format.bullet.numbered_bullet_start_with = 7
    text_frame.paragraphs.add(third_paragraph)

    presentation.save("custom_numbered_list.pptx", slides.export.SaveFormat.PPTX)

पैराग्राफ लेआउट और एंड प्रॉपर्टीज़ नियंत्रित करें

पहली पंक्ति का इंडेंट सेट करें

ParagraphFormat.indent प्रॉपर्टी का उपयोग करके पैराग्राफ की पहली पंक्ति का इंडेंट नियंत्रित किया जाता है। यह प्रॉपर्टी केवल पहली पंक्ति को पैराग्राफ के बाएँ मार्जिन के सापेक्ष लेती है। सकारात्मक मान पहली पंक्ति को दाएँ शिफ्ट करता है, जबकि बाकी पंक्तियाँ पैराग्राफ बॉडी के साथ संरेखित रहती हैं।

पूरे पैराग्राफ को ले जाने के लिए आप ParagraphFormat.margin_left प्रयोग कर सकते हैं। केवल पहली पंक्ति को ले जाने के लिए ParagraphFormat.indent उपयोग करें।

नीचे दिया गया उदाहरण कई पैराग्राफ बनाता है और विभिन्न ParagraphFormat.indent मान लागू करता है ताकि दिखाया जा सके कि पहली पंक्ति का इंडेंट पैराग्राफ लेआउट को कैसे प्रभावित करता है।

  1. एक Presentation क्लास का उदाहरण बनाएँ।
  2. लक्ष्य स्लाइड तक पहुँचें।
  3. स्लाइड में एक आयताकार AutoShape जोड़ें।
  4. शैप के TextFrame तक पहुँचें और डिफ़ॉल्ट पैराग्राफ हटाएँ।
  5. कई पैराग्राफ बनाएँ और उनके लिए विभिन्न ParagraphFormat.indent मान सेट करें।
  6. पैराग्राफ को टेक्स्ट फ्रेम में जोड़ें।
  7. संशोधित प्रस्तुति सहेजें।

यह कोड दिखाता है कि पैराग्राफ इंडेंट कैसे सेट करें:

import aspose.pydrawing as draw
import aspose.slides as slides

with slides.Presentation() as presentation:
    slide = presentation.slides[0]
    shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 420, 220)
    shape.fill_format.fill_type = slides.FillType.NO_FILL
    shape.line_format.fill_format.fill_type = slides.FillType.SOLID
    shape.line_format.fill_format.solid_fill_color.color = draw.Color.gray

    text_frame = shape.text_frame
    text_frame.text_frame_format.autofit_type = slides.TextAutofitType.SHAPE
    text_frame.paragraphs.clear()

    first_paragraph = slides.Paragraph()
    first_paragraph.text = "No first-line indent. Wrapped lines start at the same position as the first line."
    first_paragraph.paragraph_format.default_portion_format.fill_format.fill_type = slides.FillType.SOLID
    first_paragraph.paragraph_format.default_portion_format.fill_format.solid_fill_color.color = draw.Color.black
    first_paragraph.paragraph_format.margin_left = 20
    first_paragraph.paragraph_format.indent = 0

    second_paragraph = slides.Paragraph()
    second_paragraph.text = "First-line indent of 20 points. The first line moves to the right, while wrapped lines remain aligned to the paragraph body."
    second_paragraph.paragraph_format.default_portion_format.fill_format.fill_type = slides.FillType.SOLID
    second_paragraph.paragraph_format.default_portion_format.fill_format.solid_fill_color.color = draw.Color.black
    second_paragraph.paragraph_format.margin_left = 20
    second_paragraph.paragraph_format.indent = 20

    third_paragraph = slides.Paragraph()
    third_paragraph.text = "First-line indent of 40 points. This paragraph shows a larger first-line offset to make the effect easier to see."
    third_paragraph.paragraph_format.default_portion_format.fill_format.fill_type = slides.FillType.SOLID
    third_paragraph.paragraph_format.default_portion_format.fill_format.solid_fill_color.color = draw.Color.black
    third_paragraph.paragraph_format.margin_left = 20
    third_paragraph.paragraph_format.indent = 40

    text_frame.paragraphs.add(first_paragraph)
    text_frame.paragraphs.add(second_paragraph)
    text_frame.paragraphs.add(third_paragraph)

    presentation.save("paragraph_indent.pptx", slides.export.SaveFormat.PPTX)

परिणाम:

पैराग्राफों की पहली पंक्ति का इंडेंट

हेंगिंग इंडेंट सेट करें

हेंगिंग इंडेंट वह पैराग्राफ लेआउट है जिसमें पहली पंक्ति बाकी पंक्तियों से बाएं शुरू होती है। Aspose.Slides में आप इस प्रभाव को ParagraphFormat.indent प्रॉपर्टी से बनाते हैं। indent को नकारात्मक मान सेट करके पहली पंक्ति को पैराग्राफ बॉडी के सापेक्ष बाएँ ले जाएँ।

व्यवहार में, ParagraphFormat.margin_left पैराग्राफ बॉडी की बायाँ स्थिति निर्धारित करता है, और ParagraphFormat.indent पहली पंक्ति की स्थिति इसे मार्जिन के सापेक्ष तय करती है। हेंगिंग इंडेंट बनाने के लिए, सकारात्मक margin_left मान और नकारात्मक indent मान सेट करें।

यह फ़ॉर्मेटिंग बिब्लियोग्राफी, रेफ़रेंसेस, शब्दकोश प्रविष्टियों आदि के लिए उपयोगी है जहाँ रैप्ड लाइनों को पैराग्राफ बॉडी के नीचे संरेखित करना आवश्यक होता है।

  1. एक Presentation क्लास का उदाहरण बनाएँ।
  2. लक्ष्य स्लाइड तक पहुँचें।
  3. स्लाइड में एक आयताकार AutoShape जोड़ें।
  4. शैप के TextFrame तक पहुँचें और डिफ़ॉल्ट पैराग्राफ हटाएँ।
  5. प्रत्येक पैराग्राफ के लिए सकारात्मक ParagraphFormat.margin_left मान सेट करके पैराग्राफ बनाएँ।
  6. हेंगिंग इंडेंट प्रभाव बनाने के लिए नकारात्मक ParagraphFormat.indent मान सेट करें।
  7. पैराग्राफ को टेक्स्ट फ्रेम में जोड़ें।
  8. संशोधित प्रस्तुति सहेजें।

यह कोड दिखाता है कि पैराग्राफ पर हेंगिंग इंडेंट कैसे सेट करें:

import aspose.pydrawing as draw
import aspose.slides as slides

with slides.Presentation() as presentation:
    slide = presentation.slides[0]
    shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 420, 220)
    shape.fill_format.fill_type = slides.FillType.NO_FILL
    shape.line_format.fill_format.fill_type = slides.FillType.SOLID
    shape.line_format.fill_format.solid_fill_color.color = draw.Color.gray

    text_frame = shape.text_frame
    text_frame.text_frame_format.autofit_type = slides.TextAutofitType.SHAPE
    text_frame.paragraphs.clear()

    first_paragraph = slides.Paragraph()
    first_paragraph.text = "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.paragraph_format.default_portion_format.fill_format.fill_type = slides.FillType.SOLID
    first_paragraph.paragraph_format.default_portion_format.fill_format.solid_fill_color.color = draw.Color.black
    first_paragraph.paragraph_format.margin_left = 40
    first_paragraph.paragraph_format.indent = -20

    second_paragraph = slides.Paragraph()
    second_paragraph.text = "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.paragraph_format.default_portion_format.fill_format.fill_type = slides.FillType.SOLID
    second_paragraph.paragraph_format.default_portion_format.fill_format.solid_fill_color.color = draw.Color.black
    second_paragraph.paragraph_format.margin_left = 60
    second_paragraph.paragraph_format.indent = -30

    text_frame.paragraphs.add(first_paragraph)
    text_frame.paragraphs.add(second_paragraph)

    presentation.save("hanging_indent.pptx", slides.export.SaveFormat.PPTX)

परिणाम:

पैराग्राफों का हैंगिंग इंडेंट

एंड पैराग्राफ रन प्रॉपर्टीज़ सेट करें

Paragraph.end_paragraph_portion_format प्रॉपर्टी पैराग्राफ एंड मार्क की फ़ॉर्मेटिंग नियंत्रित करती है। निम्न उदाहरण दूसरे पैराग्राफ के एंड मार्क को फ़ॉन्ट साइज और लैटिन फ़ॉन्ट असाइन करता है:

  1. एक Presentation लोड करें और एक स्लाइड तक पहुँचें।
  2. एक AutoShape जोड़ें और उसका डिफ़ॉल्ट पैराग्राफ साफ़ करें।
  3. दो पैराग्राफ बनाएँ और उनमें टेक्स्ट पोर्शन जोड़ें।
  4. दूसरे पैराग्राफ के एंड मार्क के लिए एक PortionFormat बनाएँ।
  5. PortionFormat.font_height और PortionFormat.latin_font सेट करें।
  6. फॉर्मेट को Paragraph.end_paragraph_portion_format को असाइन करें और प्रस्तुति सहेजें।
import aspose.slides as slides

with slides.Presentation("Test.pptx") as presentation:
    slide = presentation.slides[0]
    shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 10, 10, 200, 250)
    text_frame = shape.text_frame
    text_frame.paragraphs.clear()

    first_paragraph = slides.Paragraph()
    first_paragraph.portions.add(slides.Portion("Sample text"))

    second_paragraph = slides.Paragraph()
    second_paragraph.portions.add(slides.Portion("Sample text 2"))

    end_paragraph_format = slides.PortionFormat()
    end_paragraph_format.font_height = 48
    end_paragraph_format.latin_font = slides.FontData("Times New Roman")
    second_paragraph.end_paragraph_portion_format = end_paragraph_format

    text_frame.paragraphs.add(first_paragraph)
    text_frame.paragraphs.add(second_paragraph)

    presentation.save("end_paragraph_format.pptx", slides.export.SaveFormat.PPTX)

रेंडर की गई लाइनों को गिनें

लाइन ब्रेकिंग और लाइनों के अंत में विराम चिह्न को नियंत्रित करने वाले पैराग्राफ नियमों के लिए देखें Control Line Breaking और Control Hanging Punctuation।

Paragraph.get_lines_count का उपयोग करके आप टेक्स्ट लेआउट के बाद पैराग्राफ द्वारा ली गई लाइनों की संख्या गिन सकते हैं, जिसमें स्वचालित रैपिंग शामिल है। यह प्रस्तुति टेम्प्लेट में टेक्स्ट लंबाई और लेआउट जाँचने के लिए उपयोगी है।

एक पैराग्राफ TextFrame.paragraphs में एक आइटम है, और यह कई रेंडर की गई लाइनों को कवर कर सकता है। पैराग्राफ के भीतर स्पष्ट लाइन ब्रेक नई लाइन बनाता है बिना नया पैराग्राफ बनाए। स्वचालित रैपिंग उपलब्ध चौड़ाई के आधार पर लाइनों का निर्माण करता है बिना टेक्स्ट में स्पष्ट लाइन ब्रेक डाले। इसलिए पैराग्राफ या लाइन‑ब्रेक कैरेक्टर्स को गिनना रेंडर की गई लाइन काउंट नहीं देता।

निम्न उदाहरण एक टेक्स्ट शैप बनाता है, उसकी लाइनों की गिनती करता है, शैप को संकरा करता है, और फिर टेक्स्ट को छोटे स्ट्रिंग से बदलता है। रैपिंग सक्षम है और ऑटोफ़िट बंद है ताकि शैप की चौड़ाई रैपिंग को नियंत्रित करे बिना टेक्स्ट को स्वतः घटाए या शैप को रिसाइज़ किए। शैप आयाम पॉइंट में हैं। अंत में, उदाहरण एक और पैराग्राफ जोड़ता है और टेक्स्ट फ्रेम में सभी लाइन काउंट जोड़ता है।

import aspose.slides as slides

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 400, 200)
    text_frame = shape.text_frame
    text_frame.text_frame_format.wrap_text = slides.NullableBool.TRUE
    text_frame.text_frame_format.autofit_type = slides.TextAutofitType.NONE

    paragraph = text_frame.paragraphs[0]
    paragraph.paragraph_format.default_portion_format.font_height = 20
    paragraph.text = "This text demonstrates how automatic wrapping changes the number of rendered lines."
    print(f"Original width: {paragraph.get_lines_count()}")

    shape.width = 150
    print(f"Narrower shape: {paragraph.get_lines_count()}")

    paragraph.text = "Short text."
    print(f"Shorter text: {paragraph.get_lines_count()}")

    second_paragraph = slides.Paragraph()
    second_paragraph.text = "Another paragraph."
    second_paragraph.paragraph_format.default_portion_format.font_height = 20
    text_frame.paragraphs.add(second_paragraph)

    total_line_count = 0
    for current_paragraph in text_frame.paragraphs:
        total_line_count += current_paragraph.get_lines_count()
    print(f"Total lines in the text frame: {total_line_count}")

इन टेक्स्ट और आयामों के साथ, शैप को संकुचित करने से लाइन काउंट बढ़ता है, जबकि छोटे स्ट्रिंग से बदलने से कम होता है। फ़ॉन्ट उपलब्धता और प्रतिस्थापन, फ़ॉन्ट आकार, मार्जिन, इंडेंटेशन, रैपिंग और ऑटोफ़िट सेटिंग्स के आधार पर सटीक काउंट बदल सकते हैं। टेम्प्लेट जाँचते समय लक्ष्य वातावरण के लिए इच्छित फ़ॉन्ट और लेआउट सेटिंग्स का उपयोग करें।

केवल लाइन काउंट यह निर्धारित नहीं करता कि टेक्स्ट कंटेनर से बाहर निकल रहा है या नहीं। उपलब्ध ऊँचाई, लाइन ऊँचाइयाँ, पैराग्राफ और लाइन स्पेसिंग, और ऑटोफ़िट व्यवहार भी महत्वपूर्ण हैं; रैपिंग निष्क्रिय होने पर एक ही लाइन उपलब्ध चौड़ाई से अधिक हो सकती है।

पैराग्राफ सामग्री आयात और निर्यात करें

HTML टेक्स्ट को पैराग्राफ में आयात करें

ParagraphCollection.add_from_html का उपयोग करके HTML मार्कअप को टेक्स्ट फ्रेम में पैराग्राफ और पोर्शन में परिवर्तित करें।

  1. एक Presentation क्लास का उदाहरण बनाएँ।
  2. एक स्लाइड तक पहुँचें और एक AutoShape जोड़ें।
  3. शैप के TextFrame तक पहुँचें और डिफ़ॉल्ट पैराग्राफ साफ़ करें।
  4. स्रोत HTML फ़ाइल पढ़ें।
  5. HTML स्ट्रिंग को ParagraphCollection.add_from_html को पास करें।
  6. संशोधित प्रस्तुति सहेजें।

यह Python उदाहरण HTML को टेक्स्ट फ्रेम में आयात करता है:

import aspose.slides as slides

with slides.Presentation() as presentation:
    slide = presentation.slides[0]
    shape_width = presentation.slide_size.size.width - 20
    shape_height = presentation.slide_size.size.height - 20
    shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 10, 10, shape_width, shape_height)
    shape.fill_format.fill_type = slides.FillType.NO_FILL
    shape.text_frame.paragraphs.clear()

    with open("file.html", "r", encoding="utf-8") as html_stream:
        html = html_stream.read()

    shape.text_frame.paragraphs.add_from_html(html)
    presentation.save("html_text.pptx", slides.export.SaveFormat.PPTX)

पैराग्राफ टेक्स्ट को HTML में निर्यात करें

ParagraphCollection.export_to_html का उपयोग करके चयनित पैराग्राफ रेंज को HTML के रूप में निर्यात करें।

  1. एक Presentation क्लास का उदाहरण बनाएँ और वांछित प्रस्तुति लोड करें।
  2. स्लाइड तक पहुँचें और वह AutoShape खोजें जो टेक्स्ट रखता है।
  3. शैप के TextFrame तक पहुँचें।
  4. शुरुआती पैराग्राफ इंडेक्स और निर्यात करने वाले पैराग्राफों की संख्या के साथ ParagraphCollection.export_to_html को कॉल करें।
  5. वापस मिली HTML स्ट्रिंग को फ़ाइल में लिखें।

यह Python उदाहरण पहले टेक्स्ट शैप से सभी पैराग्राफ निर्यात करता है:

import aspose.slides as slides

with slides.Presentation("ExportingHTMLText.pptx") as presentation:
    shape = presentation.slides[0].shapes[0]

    if isinstance(shape, slides.AutoShape) and shape.text_frame is not None:
        paragraphs = shape.text_frame.paragraphs
        html = paragraphs.export_to_html(0, paragraphs.count, None)
        with open("paragraphs.html", "w", encoding="utf-8") as html_stream:
            html_stream.write(html)
    else:
        print("The first shape is not a text shape.")

पैराग्राफ को छवि के रूप में रेंडर करें

Paragraph get_image मेथड प्रदान करता है जिससे किसी व्यक्तिगत पैराग्राफ को सीधे रेंडर किया जा सकता है। यह मेथड एक IImage लौटाता है जिसे आप फ़ाइल या स्ट्रीम में IImage.save के साथ सहेज सकते हैं। आपको कंटेनिंग शैप को रेंडर करने या बिटर को मैन्युअली क्रॉप करने की आवश्यकता नहीं है।

यदि पैराग्राफ को उसके पैरेंट कलेक्शन में नहीं पाया जाता, वैध रेंडरिंग बॉउंड्स नहीं होते, या रेंडर नहीं किया जा सकता तो get_image None लौटाता है। सहेजने से पहले परिणाम जाँचें और इमेज को कॉन्टेक्स्ट मैनेजर के रूप में उपयोग करके संसाधनों को मुक्त करें।

डिफ़ॉल्ट स्केल पर पैराग्राफ रेंडर करें

मान लीजिए हमारे पास sample.pptx नामक प्रस्तुति फ़ाइल है जिसमें एक स्लाइड है, जहाँ पहला शैप तीन पैराग्राफ वाला टेक्स्ट बॉक्स है।

तीन पैराग्राफ वाला टेक्स्ट बॉक्स

निम्न उदाहरण दूसरे पैराग्राफ को नियमित टेक्स्ट शैप में डिफ़ॉल्ट स्केल पर रेंडर करता है और PNG फ़ॉर्मेट में लौटाई गई इमेज सहेजता है:

import aspose.slides as slides

with slides.Presentation("sample.pptx") as presentation:
    shape = presentation.slides[0].shapes[0]

    if isinstance(shape, slides.AutoShape) and shape.text_frame is not None and shape.text_frame.paragraphs.count > 1:
        paragraph = shape.text_frame.paragraphs[1]
        paragraph_image = paragraph.get_image()

        if paragraph_image is not None:
            with paragraph_image:
                paragraph_image.save("paragraph.png", slides.ImageFormat.PNG)
        else:
            print("The paragraph could not be rendered.")
    else:
        print("The expected text shape or paragraph was not found.")

परिणाम:

पैराग्राफ छवि

टेबल सेल में स्केलिंग के साथ पैराग्राफ रेंडर करें

get_image में क्षैतिज और ऊर्ध्वाधर स्केल फ़ैक्टर पास करके रेंडर किए गए पैराग्राफ का आकार नियंत्रित किया जा सकता है। निम्न उदाहरण एक टेबल बनाता है, पहले सेल में पैराग्राफ को डिफ़ॉल्ट चौड़ाई और ऊँचाई के दो गुना पर रेंडर करता है, और परिणाम को PNG इमेज के रूप में सहेजता है:

import aspose.slides as slides

scale_x = 2
scale_y = 2

with slides.Presentation() as presentation:
    slide = presentation.slides[0]
    table = slide.shapes.add_table(50, 50, [300], [80])
    paragraph = table.rows[0][0].text_frame.paragraphs[0]
    paragraph.text = "Text in a table cell"

    paragraph_image = paragraph.get_image(scale_x, scale_y)
    if paragraph_image is not None:
        with paragraph_image:
            paragraph_image.save("table_paragraph.png", slides.ImageFormat.PNG)
    else:
        print("The paragraph could not be rendered.")

1 का स्केल फ़ैक्टर उस अक्ष को डिफ़ॉल्ट पिक्सेल आकार पर रखता है। उदाहरण के लिए, दोनों फ़ैक्टर 2 होने पर इमेज की चौड़ाई और ऊँचाई लगभग दो गुना हो जाती है, जिससे कुल चार गुना पिक्सेल मिलते हैं। बड़े फ़ैक्टर ज़ूम या हाई‑रेज़ॉल्यूशन आउटपुट के लिए टेक्स्ट को तेज़ बनाते हैं, लेकिन मेमोरी उपयोग और फ़ाइल आकार भी बढ़ाते हैं। 1 से नीचे के फ़ैक्टर छोटे इमेज बनाते हैं जिनमें कम विवरण होता है। समान फ़ैक्टर उपयोग करने से पैराग्राफ का अस्पेक्ट रेशियो बना रहता है; अलग-अलग क्षैतिज और ऊर्ध्वाधर फ़ैक्टर आउटपुट को स्वतंत्र रूप से खींचते हैं।

पूरा शैप रेंडर करने के लिए Shape.get_image उपयोगी रहता है जब आउटपुट में शैप की फ़िल, बॉर्डर या अन्य विज़ुअल कॉन्टेक्स्ट शामिल होना चाहिए। केवल पैराग्राफ इमेज के लिए Paragraph.get_image उपयोग करें।

अक्सर पूछे जाने वाले प्रश्न

क्या मैं टेक्स्ट फ्रेम के भीतर लाइन रैपिंग को पूरी तरह निष्क्रिय कर सकता हूँ?

हां। रैपिंग को निष्क्रिय करने के लिए TextFrameFormat.wrap_text सेट करें ताकि लाइनों का टूटना टेक्स्ट फ्रेम के किनारों पर न हो।

मैं किसी विशेष पैराग्राफ की स्लाइड पर सटीक सीमा कैसे प्राप्त करूँ?

Paragraph.get_rect का उपयोग करके पैराग्राफ का बाउंडिंग रेक्टैंगल प्राप्त करें। व्यक्तिगत पोर्शन की सीमाएँ प्राप्त करने के लिए Portion.get_rect प्रयोग करें।

पैराग्राफ संरेखण (बाएं, दाएं, केंद्र या जस्टिफाई) कहाँ नियंत्रित होता है?

ParagraphFormat.alignment पैराग्राफ‑स्तर की सेटिंग है और यह पूरे पैराग्राफ पर लागू होती है, चाहे व्यक्तिगत पोर्शन का फ़ॉर्मेटिंग कुछ भी हो।

हर लाइन में विभिन्न फ़ॉन्ट आकार वाले पोर्शन को वर्टिकली एलाइन करने के लिए देखें Align Fonts Within a Line।

क्या मैं पैराग्राफ के भाग के लिए प्रूफ़िंग भाषा सेट कर सकता हूँ?

हां। व्यक्तिगत पोर्शन के लिए PortionFormat.language_id सेट करें, जिससे एक पैराग्राफ कई भाषाओं में टेक्स्ट रख सकता है।