.NET में टेक्स्ट को कैसे फॉर्मेट करें
Aspose.Slides FOSS for .NET provides fine-grained text formatting through the PortionFormat class. A Portion पाठ की सबसे छोटी स्वतंत्र इकाई है; यह एक पैराग्राफ के भीतर एकल फ़ॉर्मेटिंग रन से मेल खाती है। यह गाइड दिखाता है कि प्रस्तुति में पाठ पर bold, italic, font size, और color फ़ॉर्मेटिंग कैसे लागू की जाए।.
स्टेप बाय स्टेप गाइड
Step 1: पैकेज स्थापित करें
dotnet add package Aspose.Slides.Fossचरण 2: टेक्स्ट फ्रेम के साथ एक शैप जोड़ें
पाठ को फ़ॉर्मेट करने से पहले, एक shape में एक 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 object. आप इसे बाद में भी के माध्यम से प्राप्त कर सकते हैं shape.TextFrame.
var tf = shape.TextFrame; // if the frame already exists
var tf = shape.AddTextFrame(""); // creates a new frameA TextFrame में एक list of Paragraph objects (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 property Latin फ़ॉन्ट परिवार सेट करता है। यदि सेट नहीं किया गया, तो प्रस्तुति थीम फ़ॉन्ट का उपयोग किया जाता है। कस्टम फ़ॉन्ट को एम्बेड किया जाना चाहिए या दर्शक मशीन पर उपलब्ध होना चाहिए।.
अक्सर पूछे जाने वाले प्रश्न
मैं फ़ॉन्ट फ़ैमिली कैसे बदलूँ?
सेट PortionFormat.LatinFont:
fmt.LatinFont = new FontData("Arial");FontData फ़ॉन्ट फ़ैमिली नाम को string के रूप में स्वीकार करता है।.
मैं पैराग्राफ अलाइनमेंट कैसे सेट करूँ?
उपयोग करें 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