PHP में PowerPoint टेक्स्ट पैराग्राफ़ प्रबंधित करें

Contents
[ ]

अवलोकन

Aspose.Slides for PHP via Java पाठ को टेक्स्ट फ्रेम, पैराग्राफ, और भागों (Portions) की पदानुक्रम में दर्शाता है:

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

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

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

कई भागों (Portions) के साथ पैराग्राफ बनाना

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

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

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

use aspose\slides\FillType;
use aspose\slides\NullableBool;
use aspose\slides\Paragraph;
use aspose\slides\Portion;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
use aspose\slides\ShapeType;

$presentation = new Presentation();
try {
    $slide = $presentation->getSlides()->get_Item(0);
    $shape = $slide->getShapes()->addAutoShape(ShapeType::Rectangle, 50, 150, 300, 150);
    $textFrame = $shape->getTextFrame();

    $firstParagraph = $textFrame->getParagraphs()->get_Item(0);
    $firstParagraph->getPortions()->add(new Portion());
    $firstParagraph->getPortions()->add(new Portion());

    $secondParagraph = new Paragraph();
    $secondParagraph->getPortions()->add(new Portion());
    $secondParagraph->getPortions()->add(new Portion());
    $secondParagraph->getPortions()->add(new Portion());
    $textFrame->getParagraphs()->add($secondParagraph);

    $thirdParagraph = new Paragraph();
    $thirdParagraph->getPortions()->add(new Portion());
    $thirdParagraph->getPortions()->add(new Portion());
    $thirdParagraph->getPortions()->add(new Portion());
    $textFrame->getParagraphs()->add($thirdParagraph);

    $paragraphCount = java_values($textFrame->getParagraphs()->getCount());
    for ($paragraphIndex = 0; $paragraphIndex < $paragraphCount; $paragraphIndex++) {
        $paragraph = $textFrame->getParagraphs()->get_Item($paragraphIndex);
        $portionCount = java_values($paragraph->getPortions()->getCount());
        for ($portionIndex = 0; $portionIndex < $portionCount; $portionIndex++) {
            $portion = $paragraph->getPortions()->get_Item($portionIndex);
            $portion->setText("Portion " . ($paragraphIndex + 1) . "." . ($portionIndex + 1));

            if ($portionIndex == 0) {
                $portion->getPortionFormat()->getFillFormat()->setFillType(FillType::Solid);
                $portion->getPortionFormat()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->RED);
                $portion->getPortionFormat()->setFontBold(NullableBool::True);
                $portion->getPortionFormat()->setFontHeight(15);
            } else if ($portionIndex == 1) {
                $portion->getPortionFormat()->getFillFormat()->setFillType(FillType::Solid);
                $portion->getPortionFormat()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.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 के माध्यम से परिभाषित किया जाता है।

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

यह PHP उदाहरण एक प्रतीक बुलेट और एक नंबरिड बुलेट बनाता है:

use aspose\slides\BulletType;
use aspose\slides\ColorType;
use aspose\slides\NullableBool;
use aspose\slides\NumberedBulletStyle;
use aspose\slides\Paragraph;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
use aspose\slides\ShapeType;

$presentation = new Presentation();
try {
    $slide = $presentation->getSlides()->get_Item(0);
    $shape = $slide->getShapes()->addAutoShape(ShapeType::Rectangle, 200, 200, 400, 200);
    $textFrame = $shape->getTextFrame();
    $textFrame->getParagraphs()->clear();

    $symbolParagraph = new Paragraph();
    $symbolParagraph->setText("Welcome to Aspose.Slides");
    $symbolParagraph->getParagraphFormat()->getBullet()->setType(BulletType::Symbol);
    $symbolParagraph->getParagraphFormat()->getBullet()->setChar("•");
    $symbolParagraph->getParagraphFormat()->setIndent(25);
    $symbolParagraph->getParagraphFormat()->getBullet()->getColor()->setColorType(ColorType::RGB);
    $symbolParagraph->getParagraphFormat()->getBullet()->getColor()->setColor(java("java.awt.Color")->BLACK);
    $symbolParagraph->getParagraphFormat()->getBullet()->setBulletHardColor(NullableBool::True);
    $symbolParagraph->getParagraphFormat()->getBullet()->setHeight(100);
    $textFrame->getParagraphs()->add($symbolParagraph);

    $numberedParagraph = new Paragraph();
    $numberedParagraph->setText("This is a numbered item");
    $numberedParagraph->getParagraphFormat()->getBullet()->setType(BulletType::Numbered);
    $numberedParagraph->getParagraphFormat()->getBullet()->setNumberedBulletStyle(NumberedBulletStyle::BulletCircleNumWDBlackPlain);
    $numberedParagraph->getParagraphFormat()->setIndent(25);
    $numberedParagraph->getParagraphFormat()->getBullet()->getColor()->setColorType(ColorType::RGB);
    $numberedParagraph->getParagraphFormat()->getBullet()->getColor()->setColor(java("java.awt.Color")->BLACK);
    $numberedParagraph->getParagraphFormat()->getBullet()->setBulletHardColor(NullableBool::True);
    $numberedParagraph->getParagraphFormat()->getBullet()->setHeight(100);
    $textFrame->getParagraphs()->add($numberedParagraph);

    $presentation->save("bulleted_and_numbered_list.pptx", SaveFormat::Pptx);
} finally {
    $presentation->dispose();
}

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

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

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

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

use aspose\slides\BulletType;
use aspose\slides\Images;
use aspose\slides\Paragraph;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
use aspose\slides\ShapeType;

$presentation = new Presentation();
try {
    $slide = $presentation->getSlides()->get_Item(0);

    $bulletImage = Images::fromFile("bullets.png");
    try {
        $presentationImage = $presentation->getImages()->addImage($bulletImage);
    } finally {
        $bulletImage->dispose();
    }

    $shape = $slide->getShapes()->addAutoShape(ShapeType::Rectangle, 200, 200, 400, 200);
    $textFrame = $shape->getTextFrame();
    $textFrame->getParagraphs()->clear();

    $paragraph = new Paragraph();
    $paragraph->setText("Welcome to Aspose.Slides");
    $paragraph->getParagraphFormat()->getBullet()->setType(BulletType::Picture);
    $paragraph->getParagraphFormat()->getBullet()->getPicture()->setImage($presentationImage);
    $paragraph->getParagraphFormat()->getBullet()->setHeight(100);
    $textFrame->getParagraphs()->add($paragraph);

    $presentation->save("picture_bullet.pptx", SaveFormat::Pptx);
    $presentation->save("picture_bullet.ppt", SaveFormat::Ppt);
} finally {
    $presentation->dispose();
}

बहु-स्तरीय सूची बनाना

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

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

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

use aspose\slides\BulletType;
use aspose\slides\FillType;
use aspose\slides\Paragraph;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
use aspose\slides\ShapeType;

$presentation = new Presentation();
try {
    $slide = $presentation->getSlides()->get_Item(0);
    $shape = $slide->getShapes()->addAutoShape(ShapeType::Rectangle, 200, 200, 400, 200);
    $textFrame = $shape->getTextFrame();
    $textFrame->getParagraphs()->clear();

    $firstParagraph = new Paragraph();
    $firstParagraph->setText("Content");
    $firstParagraph->getParagraphFormat()->getBullet()->setType(BulletType::Symbol);
    $firstParagraph->getParagraphFormat()->getBullet()->setChar("•");
    $firstParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->setFillType(FillType::Solid);
    $firstParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->BLACK);
    $firstParagraph->getParagraphFormat()->setDepth(0);

    $secondParagraph = new Paragraph();
    $secondParagraph->setText("Second level");
    $secondParagraph->getParagraphFormat()->getBullet()->setType(BulletType::Symbol);
    $secondParagraph->getParagraphFormat()->getBullet()->setChar('-');
    $secondParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->setFillType(FillType::Solid);
    $secondParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->BLACK);
    $secondParagraph->getParagraphFormat()->setDepth(1);

    $thirdParagraph = new Paragraph();
    $thirdParagraph->setText("Third level");
    $thirdParagraph->getParagraphFormat()->getBullet()->setType(BulletType::Symbol);
    $thirdParagraph->getParagraphFormat()->getBullet()->setChar("•");
    $thirdParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->setFillType(FillType::Solid);
    $thirdParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->BLACK);
    $thirdParagraph->getParagraphFormat()->setDepth(2);

    $fourthParagraph = new Paragraph();
    $fourthParagraph->setText("Fourth level");
    $fourthParagraph->getParagraphFormat()->getBullet()->setType(BulletType::Symbol);
    $fourthParagraph->getParagraphFormat()->getBullet()->setChar('-');
    $fourthParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->setFillType(FillType::Solid);
    $fourthParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->BLACK);
    $fourthParagraph->getParagraphFormat()->setDepth(3);

    $textFrame->getParagraphs()->add($firstParagraph);
    $textFrame->getParagraphs()->add($secondParagraph);
    $textFrame->getParagraphs()->add($thirdParagraph);
    $textFrame->getParagraphs()->add($fourthParagraph);

    $presentation->save("multilevel_list.pptx", SaveFormat::Pptx);
} finally {
    $presentation->dispose();
}

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

BulletFormat::setNumberedBulletStartWith का उपयोग करके नंबरिड पैराग्राफ के लिए प्रारंभिक संख्या निर्धारित की जा सकती है।

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

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

use aspose\slides\BulletType;
use aspose\slides\Paragraph;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
use aspose\slides\ShapeType;

$presentation = new Presentation();
try {
    $shape = $presentation->getSlides()->get_Item(0)->getShapes()->addAutoShape(ShapeType::Rectangle, 200, 200, 400, 200);
    $textFrame = $shape->getTextFrame();
    $textFrame->getParagraphs()->clear();

    $firstParagraph = new Paragraph();
    $firstParagraph->setText("Start at 2");
    $firstParagraph->getParagraphFormat()->getBullet()->setType(BulletType::Numbered);
    $firstParagraph->getParagraphFormat()->getBullet()->setNumberedBulletStartWith(2);
    $textFrame->getParagraphs()->add($firstParagraph);

    $secondParagraph = new Paragraph();
    $secondParagraph->setText("Start at 3");
    $secondParagraph->getParagraphFormat()->getBullet()->setType(BulletType::Numbered);
    $secondParagraph->getParagraphFormat()->getBullet()->setNumberedBulletStartWith(3);
    $textFrame->getParagraphs()->add($secondParagraph);

    $thirdParagraph = new Paragraph();
    $thirdParagraph->setText("Start at 7");
    $thirdParagraph->getParagraphFormat()->getBullet()->setType(BulletType::Numbered);
    $thirdParagraph->getParagraphFormat()->getBullet()->setNumberedBulletStartWith(7);
    $textFrame->getParagraphs()->add($thirdParagraph);

    $presentation->save("custom_numbered_list.pptx", SaveFormat::Pptx);
} finally {
    $presentation->dispose();
}

पैराग्राफ लेआउट और अंत गुण नियंत्रित करना

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

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

पूरा पैराग्राफ ले जाने के लिए ParagraphFormat::setMarginLeft का उपयोग करें। केवल पहली पंक्ति ले जाने के लिए ParagraphFormat::setIndent उपयोग करें।

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

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

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

use aspose\slides\FillType;
use aspose\slides\Paragraph;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
use aspose\slides\ShapeType;
use aspose\slides\TextAutofitType;

$presentation = new 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(java("java.awt.Color")->GRAY);

    $textFrame = $shape->getTextFrame();
    $textFrame->getTextFrameFormat()->setAutofitType(TextAutofitType::Shape);
    $textFrame->getParagraphs()->clear();

    $firstParagraph = new Paragraph();
    $firstParagraph->setText("No first-line indent. Wrapped lines start at the same position as the first line.");
    $firstParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->setFillType(FillType::Solid);
    $firstParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->BLACK);
    $firstParagraph->getParagraphFormat()->setMarginLeft(20.0);
    $firstParagraph->getParagraphFormat()->setIndent(0.0);

    $secondParagraph = new Paragraph();
    $secondParagraph->setText("First-line indent of 20 points. The first line moves to the right, while wrapped lines remain aligned to the paragraph body.");
    $secondParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->setFillType(FillType::Solid);
    $secondParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->BLACK);
    $secondParagraph->getParagraphFormat()->setMarginLeft(20.0);
    $secondParagraph->getParagraphFormat()->setIndent(20.0);

    $thirdParagraph = new Paragraph();
    $thirdParagraph->setText("First-line indent of 40 points. This paragraph shows a larger first-line offset to make the effect easier to see.");
    $thirdParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->setFillType(FillType::Solid);
    $thirdParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->BLACK);
    $thirdParagraph->getParagraphFormat()->setMarginLeft(20.0);
    $thirdParagraph->getParagraphFormat()->setIndent(40.0);

    $textFrame->getParagraphs()->add($firstParagraph);
    $textFrame->getParagraphs()->add($secondParagraph);
    $textFrame->getParagraphs()->add($thirdParagraph);

    $presentation->save("paragraph_indent.pptx", SaveFormat::Pptx);
} finally {
    $presentation->dispose();
}

परिणाम:

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

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

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

व्यावहारिक रूप से, ParagraphFormat::setMarginLeft पैराग्राफ बॉडी की बाएँ स्थिति निर्धारित करता है, और ParagraphFormat::setIndent पहली पंक्ति की स्थिति को उस मार्जिन के सापेक्ष निर्धारित करता है। हैंगिंग इंडेंट बनाने के लिए setMarginLeft को सकारात्मक मान और setIndent को नकारात्मक मान दें।

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

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

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

use aspose\slides\FillType;
use aspose\slides\Paragraph;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
use aspose\slides\ShapeType;
use aspose\slides\TextAutofitType;

$presentation = new 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(java("java.awt.Color")->GRAY);

    $textFrame = $shape->getTextFrame();
    $textFrame->getTextFrameFormat()->setAutofitType(TextAutofitType::Shape);
    $textFrame->getParagraphs()->clear();

    $firstParagraph = new Paragraph();
    $firstParagraph->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.");
    $firstParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->setFillType(FillType::Solid);
    $firstParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->BLACK);
    $firstParagraph->getParagraphFormat()->setMarginLeft(40.0);
    $firstParagraph->getParagraphFormat()->setIndent(-20.0);

    $secondParagraph = new Paragraph();
    $secondParagraph->setText("This second example uses a deeper hanging indent so the difference between the first line and the wrapped lines is easier to compare.");
    $secondParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->setFillType(FillType::Solid);
    $secondParagraph->getParagraphFormat()->getDefaultPortionFormat()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->BLACK);
    $secondParagraph->getParagraphFormat()->setMarginLeft(60.0);
    $secondParagraph->getParagraphFormat()->setIndent(-30.0);

    $textFrame->getParagraphs()->add($firstParagraph);
    $textFrame->getParagraphs()->add($secondParagraph);

    $presentation->save("hanging_indent.pptx", SaveFormat::Pptx);
} finally {
    $presentation->dispose();
}

परिणाम:

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

अंत पैराग्राफ रन गुण सेट करें

Paragraph::setEndParagraphPortionFormat पैराग्राफ के अंत चिह्न का फ़ॉर्मेट नियंत्रित करता है। निम्नलिखित PHP उदाहरण दूसरे पैराग्राफ के अंत चिह्न को फ़ॉन्ट आकार और लैटिन फ़ॉन्ट असाइन करता है:

  1. एक Presentation लोड करें और एक स्लाइड एक्सेस करें।
  2. एक AutoShape जोड़ें और उसका डिफ़ॉल्ट पैराग्राफ साफ़ करें।
  3. दो पैराग्राफ बनाएँ और उनमें टेक्स्ट भाग जोड़ें।
  4. दूसरे पैराग्राफ के अंत चिह्न के लिए एक PortionFormat बनाएँ।
  5. BasePortionFormat::setFontHeight और BasePortionFormat::setLatinFont सेट करें।
  6. Paragraph::setEndParagraphPortionFormat के साथ फ़ॉर्मेट असाइन करें और प्रस्तुति को सहेजें।
use aspose\slides\FontData;
use aspose\slides\Paragraph;
use aspose\slides\Portion;
use aspose\slides\PortionFormat;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
use aspose\slides\ShapeType;

$presentation = new Presentation("Test.pptx");
try {
    $slide = $presentation->getSlides()->get_Item(0);
    $shape = $slide->getShapes()->addAutoShape(ShapeType::Rectangle, 10, 10, 200, 250);
    $textFrame = $shape->getTextFrame();
    $textFrame->getParagraphs()->clear();

    $firstParagraph = new Paragraph();
    $firstParagraph->getPortions()->add(new Portion("Sample text"));

    $secondParagraph = new Paragraph();
    $secondParagraph->getPortions()->add(new Portion("Sample text 2"));

    $endParagraphFormat = new PortionFormat();
    $endParagraphFormat->setFontHeight(48);
    $endParagraphFormat->setLatinFont(new FontData("Times New Roman"));
    $secondParagraph->setEndParagraphPortionFormat($endParagraphFormat);

    $textFrame->getParagraphs()->add($firstParagraph);
    $textFrame->getParagraphs()->add($secondParagraph);

    $presentation->save("end_paragraph_format.pptx", SaveFormat::Pptx);
} finally {
    $presentation->dispose();
}

रेंडर की गई पंक्तियों की गिनती

पैराग्राफ नियमों के लिए जो स्वचालित रैपिंग और लाइन अंत में चिह्नों को प्रभावित करते हैं, देखें लाइन ब्रेकिंग नियंत्रण और हैंगिंग विराम चिह्न नियंत्रण।

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

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

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

use aspose\slides\NullableBool;
use aspose\slides\Paragraph;
use aspose\slides\Presentation;
use aspose\slides\ShapeType;
use aspose\slides\TextAutofitType;

$presentation = new Presentation();
try {
    $slide = $presentation->getSlides()->get_Item(0);

    $shape = $slide->getShapes()->addAutoShape(ShapeType::Rectangle, 50, 50, 400, 200);
    $textFrame = $shape->getTextFrame();
    $textFrame->getTextFrameFormat()->setWrapText(NullableBool::True);
    $textFrame->getTextFrameFormat()->setAutofitType(TextAutofitType::None);

    $paragraph = $textFrame->getParagraphs()->get_Item(0);
    $paragraph->getParagraphFormat()->getDefaultPortionFormat()->setFontHeight(20);
    $paragraph->setText("This text demonstrates how automatic wrapping changes the number of rendered lines.");
    echo "Original width: " . java_values($paragraph->getLinesCount()) . PHP_EOL;

    $shape->setWidth(150);
    echo "Narrower shape: " . java_values($paragraph->getLinesCount()) . PHP_EOL;

    $paragraph->setText("Short text.");
    echo "Shorter text: " . java_values($paragraph->getLinesCount()) . PHP_EOL;

    $secondParagraph = new Paragraph();
    $secondParagraph->setText("Another paragraph.");
    $secondParagraph->getParagraphFormat()->getDefaultPortionFormat()->setFontHeight(20);
    $textFrame->getParagraphs()->add($secondParagraph);

    $totalLineCount = 0;
    for ($i = 0; $i < java_values($textFrame->getParagraphs()->getCount()); $i++) {
        $currentParagraph = $textFrame->getParagraphs()->get_Item($i);
        $totalLineCount += java_values($currentParagraph->getLinesCount());
    }
    echo "Total lines in the text frame: " . $totalLineCount . PHP_EOL;
} finally {
    $presentation->dispose();
}

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

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

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

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

ParagraphCollection::addFromHtml का उपयोग करके HTML मार्कअप को टेक्स्ट फ्रेम में पैराग्राफ और भागों में परिवर्तित किया जा सकता है।

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

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

use aspose\slides\FillType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
use aspose\slides\ShapeType;

$presentation = new Presentation();
try {
    $slide = $presentation->getSlides()->get_Item(0);
    $shapeWidth = java_values($presentation->getSlideSize()->getSize()->getWidth()) - 20;
    $shapeHeight = java_values($presentation->getSlideSize()->getSize()->getHeight()) - 20;
    $shape = $slide->getShapes()->addAutoShape(ShapeType::Rectangle, 10, 10, $shapeWidth, $shapeHeight);
    $shape->getFillFormat()->setFillType(FillType::NoFill);
    $shape->getTextFrame()->getParagraphs()->clear();

    $html = file_get_contents("file.html");
    if ($html !== false) {
        $shape->getTextFrame()->getParagraphs()->addFromHtml($html);
        $presentation->save("html_text.pptx", SaveFormat::Pptx);
    } else {
        echo "The HTML file could not be read.";
    }
} finally {
    $presentation->dispose();
}

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

ParagraphCollection::exportToHtml का उपयोग करके चयनित पैराग्राफ रेंज को HTML के रूप में निर्यात किया जा सकता है।

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

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

use aspose\slides\Presentation;

$presentation = new Presentation("ExportingHTMLText.pptx");
try {
    $shape = $presentation->getSlides()->get_Item(0)->getShapes()->get_Item(0);

    if (java_instanceof($shape, new JavaClass("com.aspose.slides.AutoShape"))) {
        $textFrame = $shape->getTextFrame();
        if (!java_is_null($textFrame)) {
            $paragraphs = $textFrame->getParagraphs();
            $html = $paragraphs->exportToHtml(0, $paragraphs->getCount(), null);
            if (file_put_contents("paragraphs.html", $html) === false) {
                echo "The HTML file could not be written.";
            }
        } else {
            echo "The first shape does not contain a text frame.";
        }
    } else {
        echo "The first shape is not a text shape.";
    }
} finally {
    $presentation->dispose();
}

पैराग्राफ को इमेज के रूप में रेंडर करना

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

यदि पैराग्राफ उसके पैरेंट संग्रह में नहीं मिला, मान्य रेंडरिंग बाउंड्स नहीं हैं, या रेंडर नहीं किया जा सकता तो Paragraph::getImage null लौटाता है। सहेजने से पहले परिणाम की जाँच करें और उपयोग के बाद लौटाए गए इमेज को डिस्पोज़ करें।

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

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

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

निम्नलिखित PHP उदाहरण डिफ़ॉल्ट स्केल पर दूसरे पैराग्राफ को सामान्य टेक्स्ट शैप में रेंडर करता है और PNG फ़ॉर्मेट में इमेज सहेजता है। finally ब्लॉक इमेज को सही तरीके से डिस्पोज़ करना सुनिश्चित करता है।

use aspose\slides\ImageFormat;
use aspose\slides\Presentation;

$presentation = new Presentation("sample.pptx");
try {
    $shape = $presentation->getSlides()->get_Item(0)->getShapes()->get_Item(0);

    if (java_instanceof($shape, new JavaClass("com.aspose.slides.AutoShape"))) {
        $textFrame = $shape->getTextFrame();
        if (!java_is_null($textFrame) && java_values($textFrame->getParagraphs()->getCount()) > 1) {
            $paragraph = $textFrame->getParagraphs()->get_Item(1);
            $paragraphImage = $paragraph->getImage();

            if (!java_is_null($paragraphImage)) {
                try {
                    $paragraphImage->save("paragraph.png", ImageFormat::Png);
                } finally {
                    $paragraphImage->dispose();
                }
            } else {
                echo "The paragraph could not be rendered.";
            }
        } else {
            echo "The expected paragraph was not found.";
        }
    } else {
        echo "The first shape is not a text shape.";
    }
} finally {
    $presentation->dispose();
}

परिणाम:

पैराग्राफ इमेज

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

Paragraph::getImage ओवरलोड का उपयोग करें जो $scaleX और $scaleY पैरामीटर स्वीकार करता है ताकि क्षैतिज और लंबवत स्केल फैक्टर सेट किए जा सकें। निम्नलिखित PHP उदाहरण एक टेबल बनाता है, पहले सेल में पैराग्राफ को डिफ़ॉल्ट चौड़ाई और ऊँचाई के दो गुना स्केल पर रेंडर करता है, और परिणाम PNG इमेज के रूप में सहेजता है।

use aspose\slides\ImageFormat;
use aspose\slides\Presentation;

$scaleX = 2;
$scaleY = 2;

$presentation = new Presentation();
try {
    $slide = $presentation->getSlides()->get_Item(0);
    $table = $slide->getShapes()->addTable(50, 50, array(300), array(80));
    $paragraph = $table->get_Item(0, 0)->getTextFrame()->getParagraphs()->get_Item(0);
    $paragraph->setText("Text in a table cell");

    $paragraphImage = $paragraph->getImage($scaleX, $scaleY);
    if (!java_is_null($paragraphImage)) {
        try {
            $paragraphImage->save("table_paragraph.png", ImageFormat::Png);
        } finally {
            $paragraphImage->dispose();
        }
    } else {
        echo "The paragraph could not be rendered.";
    }
} finally {
    $presentation->dispose();
}

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

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

FAQ

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

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

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

पैराग्राफ की बाउंडिंग रेक्टैंगल प्राप्त करने के लिए Paragraph::getRect का उपयोग करें। व्यक्तिगत भाग की बाउंड्स के लिए Portion::getRect देखें।

पैराग्राफ अलाइनमेंट (बाएँ, दाएँ, मध्य, या जस्टिफ़ाय) कहाँ नियंत्रित होता है?

ParagraphFormat::setAlignment पैराग्राफ‑स्तर की सेटिंग है और व्यक्तिगत भाग फ़ॉर्मेटिंग की परवाह किए बिना पूरे पैराग्राफ पर लागू होती है।

विभिन्न फ़ॉन्ट आकार वाले भागों को प्रत्येक पंक्ति में वर्टिकली एलाइन करने के लिए देखें लाइन के भीतर फ़ॉन्ट एलाइन करना।

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

हाँ। व्यक्तिगत भागों के लिए BasePortionFormat::setLanguageId सेट करें, जिससे एक पैराग्राफ कई भाषाओं में टेक्स्ट रख सकता है।