जावा का उपयोग करके प्रस्तुतियों में टेक्स्ट बॉक्स प्रबंधित करें
परिचय
Slides पर टेक्स्ट आमतौर पर टेक्स्ट बॉक्स या शैप्स में होते हैं। इसलिए, स्लाइड में टेक्स्ट जोड़ने के लिए आपको पहले एक टेक्स्ट बॉक्स जोड़ना होगा और फिर उसके अंदर टेक्स्ट डालना होगा। Aspose.Slides for Java IAutoShape इंटरफ़ेस प्रदान करता है जो आपको टेक्स्ट वाला शैप जोड़ने की अनुमति देता है।
Info
Aspose.Slides additionally IShape इंटरफ़ेस प्रदान करता है जो आपको स्लाइड्स में शैप्स जोड़ने देता है। हालांकि,IShape इंटरफ़ेस के माध्यम से जोड़े गए सभी शैप्स टेक्स्ट धारण नहीं कर सकते। लेकिन IAutoShape इंटरफ़ेस के माध्यम से जोड़े गए शैप्स में टेक्स्ट हो सकता है।
Note
इसलिए, जब आप ऐसे शैप को टार्गेट कर रहे हों जिसमें आप टेक्स्ट जोड़ना चाहते हैं, तो आपको यह जांचना और सुनिश्चित करना चाहिए कि वहIAutoShape इंटरफ़ेस के द्वारा कास्ट किया गया है। तभी आप TextFrame, जो IAutoShape की एक प्रॉपर्टी है, के साथ काम कर पाएँगे। इस पृष्ठ के Update Text सेक्शन को देखें।
स्लाइड पर एक टेक्स्ट बॉक्स बनाएँ
स्लाइड पर टेक्स्ट बॉक्स बनाने के लिए निम्नलिखित चरणों का पालन करें:
- Presentation क्लास की एक इंस्टेंस बनाएँ।
- नई बनाई गई प्रेजेंटेशन की पहली स्लाइड के लिए रेफ़रेंस प्राप्त करें।
- निर्दिष्ट स्थिति पर
Rectangleके रूप मेंShapeTypeसेट करके एक IAutoShape ऑब्जेक्ट जोड़ें और नए जोड़े गएIAutoShapeऑब्जेक्ट का रेफ़रेंस प्राप्त करें। IAutoShapeऑब्जेक्ट मेंTextFrameप्रॉपर्टी जोड़ें जिसमें टेक्स्ट होगा। नीचे वाले उदाहरण में हमने यह टेक्स्ट जोड़ा: Aspose TextBox- अंत में,
Presentationऑब्जेक्ट के माध्यम से PPTX फ़ाइल लिखें।
ऊपर वर्णित चरणों का एक जावा इम्प्लीमेंटेशन यह दिखाता है कि स्लाइड में टेक्स्ट कैसे जोड़े:
// प्रस्तुति का उदाहरण बनाता है
Presentation pres = new Presentation();
try {
// प्रस्तुति में पहली स्लाइड प्राप्त करता है
ISlide sld = pres.getSlides().get_Item(0);
// प्रकार को Rectangle सेट करके एक AutoShape जोड़ता है
IAutoShape ashp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 150, 50);
// Rectangle में TextFrame जोड़ता है
ashp.addTextFrame(" ");
// टेक्स्ट फ़्रेम तक पहुँचता है
ITextFrame txtFrame = ashp.getTextFrame();
// टेक्स्ट फ़्रेम के लिए Paragraph ऑब्जेक्ट बनाता है
IParagraph para = txtFrame.getParagraphs().get_Item(0);
// पैराग्राफ के लिए Portion ऑब्जेक्ट बनाता है
IPortion portion = para.getPortions().get_Item(0);
// टेक्स्ट सेट करता है
portion.setText("Aspose TextBox");
// प्रस्तुति को डिस्क पर सहेजता है
pres.save("TextBox_out.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
टेक्स्ट बॉक्स शैप की जाँच करें
Aspose.Slides IAutoShape इंटरफ़ेस से isTextBox मेथड प्रदान करता है, जिससे आप शैप्स की जांच करके टेक्स्ट बॉक्स की पहचान कर सकते हैं।

यह जावा कोड दर्शाता है कि कैसे जाँचें कि कोई शैप टेक्स्ट बॉक्स के रूप में बनाया गया है या नहीं:
Presentation presentation = new Presentation("sample.pptx");
try {
ForEach.shape(presentation, (shape, slide, index) -> {
if (shape instanceof IAutoShape) {
IAutoShape autoShape = (IAutoShape) shape;
System.out.println(autoShape.isTextBox() ? "shape is a text box" : "shape is not a text box");
}
});
} finally {
presentation.dispose();
}
ध्यान दें कि यदि आप केवल addAutoShape मेथड का उपयोग करके IShapeCollection इंटरफ़ेस से एक ऑटॉशैप जोड़ते हैं, तो ऑटॉशैप का isTextBox मेथड false लौटाएगा। हालाँकि, जब आप addTextFrame मेथड या setText मेथड से ऑटॉशैप में टेक्स्ट जोड़ते हैं, तो isTextBox प्रॉपर्टी true लौटाएगी।
Presentation presentation = new Presentation();
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape1 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 10, 100, 40);
// shape1.isTextBox() false लौटाता है
shape1.addTextFrame("shape 1");
// shape1.isTextBox() true लौटाता है
IAutoShape shape2 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 110, 100, 40);
// shape2.isTextBox() false लौटाता है
shape2.getTextFrame().setText("shape 2");
// shape2.isTextBox() true लौटाता है
IAutoShape shape3 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 210, 100, 40);
// shape3.isTextBox() false लौटाता है
shape3.addTextFrame("");
// shape3.isTextBox() false लौटाता है
IAutoShape shape4 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 310, 100, 40);
// shape4.isTextBox() false लौटाता है
shape4.getTextFrame().setText("");
// shape4.isTextBox() false लौटाता है
टेक्स्ट बॉक्स में कॉलम जोड़ें
Aspose.Slides ITextFrameFormat इंटरफ़ेस और TextFrameFormat क्लास से ColumnCount और ColumnSpacing प्रॉपर्टीज़ प्रदान करता है जो आपको टेक्स्टबॉक्स में कॉलम जोड़ने की अनुमति देती हैं। आप टेक्स्ट बॉक्स में कॉलम की संख्या और कॉलमों के बीच के स्पेसिंग को पॉइंट्स में निर्दिष्ट कर सकते हैं।
यह जावा कोड उपर्युक्त ऑपरेशन को दर्शाता है:
Presentation pres = new Presentation();
try {
// प्रस्तुति में पहली स्लाइड प्राप्त करता है
ISlide slide = pres.getSlides().get_Item(0);
// प्रकार को Rectangle सेट करके AutoShape जोड़ता है
IAutoShape aShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 300, 300);
// Rectangle में TextFrame जोड़ता है
aShape.addTextFrame("All these columns are limited to be within a single text container -- " +
"you can add or delete text and the new or remaining text automatically adjusts " +
"itself to flow within the container. You cannot have text flow from one container " +
"to other though -- we told you PowerPoint's column options for text are limited!");
// TextFrame का टेक्स्ट फ़ॉर्मेट प्राप्त करता है
ITextFrameFormat format = aShape.getTextFrame().getTextFrameFormat();
// TextFrame में कॉलमों की संख्या निर्दिष्ट करता है
format.setColumnCount(3);
// कॉलमों के बीच का अंतराल निर्दिष्ट करता है
format.setColumnSpacing(10);
// प्रस्तुति को सहेजता है
pres.save("ColumnCount.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
टेक्स्ट फ्रेम में कॉलम जोड़ें
Aspose.Slides for Java ITextFrameFormat इंटरफ़ेस से ColumnCount प्रॉपर्टी प्रदान करता है, जिससे आप टेक्स्ट फ्रेम में कॉलम जोड़ सकते हैं। इस प्रॉपर्टी के माध्यम से आप टेक्स्ट फ्रेम में अपनी इच्छित कॉलम संख्या निर्दिष्ट कर सकते हैं।
यह जावा कोड दिखाता है कि टेक्स्ट फ्रेम के भीतर एक कॉलम कैसे जोड़ा जाए:
String outPptxFileName = "ColumnsTest.pptx";
Presentation pres = new Presentation();
try {
IAutoShape shape1 = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 300, 300);
TextFrameFormat format = (TextFrameFormat)shape1.getTextFrame().getTextFrameFormat();
format.setColumnCount(2);
shape1.getTextFrame().setText("All these columns are forced to stay within a single text container -- " +
"you can add or delete text - and the new or remaining text automatically adjusts " +
"itself to stay within the container. You cannot have text spill over from one container " +
"to other, though -- because PowerPoint's column options for text are limited!");
pres.save(outPptxFileName, SaveFormat.Pptx);
Presentation test = new Presentation(outPptxFileName);
try {
IAutoShape autoShape = ((AutoShape)test.getSlides().get_Item(0).getShapes().get_Item(0));
Assert.assertTrue(2 == autoShape.getTextFrame().getTextFrameFormat().getColumnCount());
Assert.assertTrue(Double.NaN == autoShape.getTextFrame().getTextFrameFormat().getColumnSpacing());
} finally {
if (test != null) test.dispose();
}
format.setColumnSpacing(20);
pres.save(outPptxFileName, SaveFormat.Pptx);
Presentation test1 = new Presentation(outPptxFileName);
try {
IAutoShape autoShape = ((AutoShape)test1.getSlides().get_Item(0).getShapes().get_Item(0));
Assert.assertTrue(2 == autoShape.getTextFrame().getTextFrameFormat().getColumnCount());
Assert.assertTrue(20 == autoShape.getTextFrame().getTextFrameFormat().getColumnSpacing());
} finally {
if (test1 != null) test1.dispose();
}
format.setColumnCount(3);
format.setColumnSpacing(15);
pres.save(outPptxFileName, SaveFormat.Pptx);
Presentation test2 = new Presentation(outPptxFileName);
try {
IAutoShape autoShape = ((AutoShape)test2.getSlides().get_Item(0).getShapes().get_Item(0));
Assert.assertTrue(3 == autoShape.getTextFrame().getTextFrameFormat().getColumnCount());
Assert.assertTrue(15 == autoShape.getTextFrame().getTextFrameFormat().getColumnSpacing());
} finally {
if (test2 != null) test2.dispose();
}
} finally {
if (pres != null) pres.dispose();
}
टेक्स्ट अपडेट करें
Aspose.Slides आपको टेक्स्ट बॉक्स में मौजूद टेक्स्ट या पूरी प्रेजेंटेशन में सभी टेक्स्ट को बदलने या अपडेट करने की अनुमति देता है।
यह जावा कोड दिखाता है कि कैसे एक प्रेजेंटेशन में सभी टेक्स्ट को अपडेट या बदलें:
Presentation pres = new Presentation("text.pptx");
try {
for (ISlide slide : pres.getSlides())
{
for (IShape shape : slide.getShapes())
{
if (shape instanceof IAutoShape) //जाँचता है कि शैप टेक्स्ट फ्रेम (IAutoShape) को सपोर्ट करता है।
{
IAutoShape autoShape = (IAutoShape)shape;
for (IParagraph paragraph : autoShape.getTextFrame().getParagraphs()) //टेक्स्ट फ्रेम में पैराग्राफों पर इटरेट करता है
{
for (IPortion portion : paragraph.getPortions()) //पैराग्राफ में प्रत्येक पोर्शन पर इटरेट करता है
{
portion.setText(portion.getText().replace("years", "months")); //टेक्स्ट बदलता है
portion.getPortionFormat().setFontBold(NullableBool.True); //फ़ॉर्मेटिंग बदलता है
}
}
}
}
}
//संशोधित प्रस्तुति को सहेजता है
pres.save("text-changed.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
हाइपरलिंक के साथ टेक्स्ट बॉक्स जोड़ें
आप टेक्स्ट बॉक्स के भीतर एक लिंक सम्मिलित कर सकते हैं। जब टेक्स्ट बॉक्स पर क्लिक किया जाता है, तो उपयोगकर्ता उस लिंक को खोलने के लिए निर्देशित होते हैं।
एक लिंक वाला टेक्स्ट बॉक्स जोड़ने के लिए इन चरणों का पालन करें:
Presentationक्लास की एक इंस्टेंस बनाएँ।- नई बनाई गई प्रेजेंटेशन की पहली स्लाइड के लिए रेफ़रेंस प्राप्त करें।
- स्लाइड पर निर्दिष्ट स्थिति पर
ShapeTypeकोRectangleसेट करके एकAutoShapeऑब्जेक्ट जोड़ें और नए जोड़े गये AutoShape ऑब्जेक्ट का रेफ़रेंस प्राप्त करें। AutoShapeऑब्जेक्ट में एकTextFrameजोड़ें जिसमें डिफ़ॉल्ट टेक्स्ट Aspose TextBox हो।IHyperlinkManagerक्लास की एक इंस्टेंस बनाएँ।IHyperlinkManagerऑब्जेक्ट को उसTextFrameके इच्छित भाग से संबंधित HyperlinkClick प्रॉपर्टी को असाइन करें।- अंत में,
Presentationऑब्जेक्ट के माध्यम से PPTX फ़ाइल लिखें।
यह जावा कोड—उपरोक्त चरणों का इम्प्लीमेंटेशन—दिखाता है कि स्लाइड में हाइपरलिंक के साथ टेक्स्ट बॉक्स कैसे जोड़ें:
// PPTX का प्रतिनिधित्व करने वाली Presentation क्लास का उदाहरण बनाता है
Presentation pres = new Presentation();
try {
// प्रस्तुति में पहली स्लाइड प्राप्त करता है
ISlide slide = pres.getSlides().get_Item(0);
// प्रकार को Rectangle सेट करके एक AutoShape ऑब्जेक्ट जोड़ता है
IShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 150, 150, 150, 50);
// शेप को AutoShape में कास्ट करता है
IAutoShape pptxAutoShape = (IAutoShape)shape;
// AutoShape से जुड़े ITextFrame प्रॉपर्टी तक पहुँचता है
pptxAutoShape.addTextFrame("");
ITextFrame textFrame = pptxAutoShape.getTextFrame();
// फ़्रेम में कुछ टेक्स्ट जोड़ता है
textFrame.getParagraphs().get_Item(0).getPortions().get_Item(0).setText("Aspose.Slides");
// पोर्शन टेक्स्ट के लिए हाइपरलिंक सेट करता है
IHyperlinkManager hyperlinkManager = textFrame.getParagraphs().get_Item(0).getPortions().get_Item(0).
getPortionFormat().getHyperlinkManager();
hyperlinkManager.setExternalHyperlinkClick("http://www.aspose.com");
// PPTX प्रस्तुति को सहेजता है
pres.save("hLink_out.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
अक्सर पूछे जाने वाले प्रश्न
मास्टर स्लाइड्स के साथ काम करते समय टेक्स्ट बॉक्स और टेक्स्ट प्लेसहोल्डर में क्या अंतर है?
एक placeholder मास्टर से शैली/स्थिति विरासत में लेता है और इसे लेआउट्स पर ओवरराइड किया जा सकता है, जबकि एक सामान्य टेक्स्ट बॉक्स विशिष्ट स्लाइड पर स्वतंत्र ऑब्जेक्ट है और लेआउट बदलने पर नहीं बदलता।
मैं प्रेजेंटेशन में चार्ट्स, टेबल्स और SmartArt के अंदर के टेक्स्ट को छुए बिना टेक्स्ट का बल्क रिप्लेसमेंट कैसे करूँ?
ऑटो‑शैप्स जिनके पास टेक्स्ट फ्रेम हैं, उन्हें ही इटरेट करें और एम्बेडेड ऑब्जेक्ट्स (चार्ट्स, टेबल्स, SmartArt) को उनके संग्रहों को अलग‑अलग ट्रैवर्स करके या उन ऑब्जेक्ट प्रकारों को स्किप करके बाहर रखें।