.NET में टेक्स्ट को फ़ॉर्मेट कैसे करें

.NET में टेक्स्ट को फ़ॉर्मेट कैसे करें

Aspose.Slides FOSS for .NET PortionFormat क्लास के माध्यम से सूक्ष्म-स्तरीय टेक्स्ट फ़ॉर्मेटिंग प्रदान करता है। Portion टेक्स्ट की सबसे छोटी स्वतंत्र इकाई है; यह पैराग्राफ के भीतर एक एकल फ़ॉर्मेटिंग रन से मेल खाती है। यह गाइड दर्शाता है कि प्रस्तुति में टेक्स्ट पर बोल्ड, इटैलिक, फ़ॉन्ट आकार और रंग फ़ॉर्मेटिंग कैसे लागू की जाए।

चरण-दर-चरण गाइड

चरण 1: पैकेज स्थापित करें

dotnet add package Aspose.Slides.Foss

चरण 2: टेक्स्ट फ्रेम के साथ एक आकार जोड़ें

टेक्स्ट को फॉर्मेट करने से पहले, एक आकार में TextFrame होना चाहिए। एक बनाने के लिए shape.AddTextFrame() का उपयोग करें।

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;

using var prs = new Presentation();
var slide = prs.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 500, 150);
var tf = shape.AddTextFrame("Default text: will be formatted");
prs.Save("output.pptx", SaveFormat.Pptx);

चरण 3: TextFrame तक पहुँचें

shape.AddTextFrame() TextFrame ऑब्जेक्ट लौटाता है। आप इसे बाद में shape.TextFrame के माध्यम से भी प्राप्त कर सकते हैं।

var tf = shape.TextFrame;          // if the frame already exists
var tf = shape.AddTextFrame("");   // creates a new frame

एक TextFrame में Paragraph वस्तुओं (tf.Paragraphs) की सूची होती है। प्रत्येक Paragraph में Portion वस्तुएँ (paragraph.Portions) होती हैं।


चरण 4: बोल्ड और इटैलिक फ़ॉर्मेटिंग लागू करें

उपयोग करें PortionFormat.FontBold और PortionFormat.FontItalic। ये गुण NullableBool.True, NullableBool.False, या NullableBool.NotDefined (मास्टर से विरासत में) स्वीकार करते हैं।

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;

using var prs = new Presentation();
var slide = prs.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 500, 150);
var tf = shape.AddTextFrame("Bold and italic text");

var fmt = tf.Paragraphs[0].Portions[0].PortionFormat;
fmt.FontBold = NullableBool.True;
fmt.FontItalic = NullableBool.True;

prs.Save("bold-italic.pptx", SaveFormat.Pptx);

चरण 5: फ़ॉन्ट आकार और रंग सेट करें

आकार (पॉइंट्स में) के लिए PortionFormat.FontHeight सेट करें और रंग के लिए FillFormat का उपयोग करें।

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Drawing;
using Aspose.Slides.Foss.Export;

using var prs = new Presentation();
var slide = prs.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 500, 150);
var tf = shape.AddTextFrame("Large corporate-blue heading");

var fmt = tf.Paragraphs[0].Portions[0].PortionFormat;
fmt.FontHeight = 32;                          // 32pt font
fmt.FontBold = NullableBool.True;
fmt.FillFormat.FillType = FillType.Solid;
fmt.FillFormat.SolidFillColor.Color = Color.FromArgb(255, 0, 70, 127);

prs.Save("colored-text.pptx", SaveFormat.Pptx);

Color.FromArgb(alpha, red, green, blue) प्रत्येक चैनल के लिए 0‑255 मान स्वीकार करता है।


चरण 6: एक पैराग्राफ में कई भाग

एक पैराग्राफ में विभिन्न स्वरूपण के साथ कई भाग हो सकते हैं। एक नया Portion पैराग्राफ के Portions संग्रह में जोड़ें:

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Drawing;
using Aspose.Slides.Foss.Export;

using var prs = new Presentation();
var slide = prs.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 600, 100);
var tf = shape.AddTextFrame("");  // start with empty frame

var paragraph = tf.Paragraphs[0];

// First portion: normal text
var portion1 = paragraph.Portions[0];
portion1.Text = "Normal text followed by ";
portion1.PortionFormat.FontHeight = 20;

// Second portion: bold red text
var portion2 = new Portion();
portion2.Text = "bold red text";
portion2.PortionFormat.FontHeight = 20;
portion2.PortionFormat.FontBold = NullableBool.True;
portion2.PortionFormat.FillFormat.FillType = FillType.Solid;
portion2.PortionFormat.FillFormat.SolidFillColor.Color = Color.FromArgb(255, 200, 0, 0);
paragraph.Portions.Add(portion2);

prs.Save("mixed-format.pptx", SaveFormat.Pptx);

सामान्य समस्याएँ और समाधान

रंग सेट करने के बाद भी टेक्स्ट काला दिख रहा है

रंग असाइन करने से पहले सुनिश्चित करें कि FillFormat.FillType = FillType.Solid सेट हो। फ़िल टाइप सेट किए बिना, रंग परिवर्तन का कोई प्रभाव नहीं हो सकता।

NullableBool.True बनाम true

PortionFormat.FontBold अपेक्षा करता है NullableBool.True, न कि C# true। C# true को असाइन करने से कंपाइल नहीं होगा क्योंकि प्रकार असंगत हैं।

फ़ॉन्ट सहेजी गई फ़ाइल में नहीं दिखता

LatinFont प्रॉपर्टी लैटिन फ़ॉन्ट फ़ैमिली सेट करती है। यदि सेट नहीं किया गया है, तो प्रस्तुति थीम फ़ॉन्ट का उपयोग किया जाता है। कस्टम फ़ॉन्ट्स को एम्बेड किया जाना चाहिए या दर्शक मशीन पर उपलब्ध होना चाहिए।


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

मैं फ़ॉन्ट फ़ैमिली कैसे बदलूँ?

सेट PortionFormat.LatinFont:

fmt.LatinFont = new FontData("Arial");

FontData फ़ॉन्ट फ़ैमिली नाम को स्ट्रिंग के रूप में स्वीकार करता है।

मैं पैराग्राफ संरेखण कैसे सेट करूँ?

उपयोग करें ParagraphFormat.Alignment:

tf.Paragraphs[0].ParagraphFormat.Alignment = TextAlignment.Center;

समर्थित मान: Left, Center, Right, Justify.

मैं लाइन स्पेसिंग कैसे सेट करूँ?

ParagraphFormat.SpaceBefore (पैराग्राफ से पहले बिंदु) या ParagraphFormat.SpaceAfter (पैराग्राफ के बाद बिंदु) का उपयोग करें:

tf.Paragraphs[0].ParagraphFormat.SpaceBefore = 12;   // 12pt before
tf.Paragraphs[0].ParagraphFormat.SpaceAfter = 6;     // 6pt after

संबंधित देखें

 हिन्दी