إدارة فقرات نص PowerPoint باستخدام JavaScript
نظرة عامة
Aspose.Slides for Node.js via Java يمثل النص كسلسلة من إطارات النص، الفقرات، والأقسام:
- TextFrame يمثل حاوية النص في الشكل ويوفر الوصول إلى مجموعة الفقرات الخاصة به.
- Paragraph يمثل فقرة واحدة في إطار النص ويوفر الوصول إلى أقسامها وتنسيق الفقرة.
- Portion يمثل تشغيل نص داخل الفقرة. يمكن لكل قسم أن يحتوي نصاً وتنسيقاً على مستوى الأحرف.
وبالتالي يمكن لفقرة أن تحتوي نصاً بخطوط، ألوان، أحجام، وتنسيقات أخرى مختلفة باستخدام أقسام متعددة.
إنشاء وتنسيق الفقرات
إنشاء فقرات مع أقسام متعددة
الخطوات التالية تنشئ إطار نص يحتوي على ثلاث فقرات، كل منها يحتوي على ثلاث أقسام:
- إنشاء مثال من الفئة Presentation.
- الوصول إلى الشريحة المطلوبة عبر فهرسها.
- إضافة AutoShape مستطيلة إلى الشريحة.
- الوصول إلى TextFrame الخاص بالشكل.
- استخدام الفقرة الافتراضية وإضافة كائنين إضافيين من نوع Paragraph إلى إطار النص.
- إضافة ما يكفي من كائنات Portion لكل فقرة لتحتوي على ثلاث أقسام. الفقرة الافتراضية تحتوي بالفعل على قسم فارغ واحد.
- تعيين نص كل قسم.
- تطبيق تنسيق على مستوى الأحرف عبر Portion.getPortionFormat.
- حفظ العرض التقديمي المعدل.
هذا المثال بلغة JavaScript يطبق الخطوات:
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 150, 300, 150);
const textFrame = shape.getTextFrame();
const firstParagraph = textFrame.getParagraphs().get_Item(0);
firstParagraph.getPortions().add(new aspose.slides.Portion());
firstParagraph.getPortions().add(new aspose.slides.Portion());
const secondParagraph = new aspose.slides.Paragraph();
secondParagraph.getPortions().add(new aspose.slides.Portion());
secondParagraph.getPortions().add(new aspose.slides.Portion());
secondParagraph.getPortions().add(new aspose.slides.Portion());
textFrame.getParagraphs().add(secondParagraph);
const thirdParagraph = new aspose.slides.Paragraph();
thirdParagraph.getPortions().add(new aspose.slides.Portion());
thirdParagraph.getPortions().add(new aspose.slides.Portion());
thirdParagraph.getPortions().add(new aspose.slides.Portion());
textFrame.getParagraphs().add(thirdParagraph);
const paragraphCount = textFrame.getParagraphs().getCount();
for (let paragraphIndex = 0; paragraphIndex < paragraphCount; paragraphIndex++) {
const paragraph = textFrame.getParagraphs().get_Item(paragraphIndex);
const portionCount = paragraph.getPortions().getCount();
for (let portionIndex = 0; portionIndex < portionCount; portionIndex++) {
const portion = paragraph.getPortions().get_Item(portionIndex);
portion.setText("Portion " + (paragraphIndex + 1) + "." + (portionIndex + 1));
if (portionIndex === 0) {
portion.getPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "RED"));
portion.getPortionFormat().setFontBold(java.newByte(aspose.slides.NullableBool.True));
portion.getPortionFormat().setFontHeight(15);
} else if (portionIndex === 1) {
portion.getPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLUE"));
portion.getPortionFormat().setFontItalic(java.newByte(aspose.slides.NullableBool.True));
portion.getPortionFormat().setFontHeight(18);
}
}
}
presentation.save("paragraphs_with_portions.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
إنشاء قوائم نقطية ورقمية
إنشاء قائمة نقطية أو رقمية
تُسهِّل النقاط والترقيم قراءة العناصر المرتبطة. في Aspose.Slides، يتم تعريف إعدادات القائمة عبر BulletFormat.
- إنشاء مثال من الفئة Presentation.
- الوصول إلى الشريحة المطلوبة عبر فهرسها.
- إضافة AutoShape إلى الشريحة المحددة.
- الوصول إلى TextFrame الخاص بالشكل.
- إزالة الفقرة الافتراضية من إطار النص.
- إنشاء Paragraph لرمز نقطة.
- تعيين BulletFormat.setType إلى BulletType.Symbol وتحديد حرف النقطة.
- تعيين نص الفقرة، والمسافة البادئة، ولون النقطة، وارتفاع النقطة.
- إضافة الفقرة إلى إطار النص.
- إنشاء فقرة ثانية وتعيين BulletFormat.setType إلى BulletType.Numbered.
- تكوين نمط النقطة الرقمية وإضافة الفقرة إلى إطار النص.
- حفظ العرض التقديمي.
هذا المثال بلغة JavaScript ينشئ نقطة رمز ونقطة رقمية:
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 200, 200, 400, 200);
const textFrame = shape.getTextFrame();
textFrame.getParagraphs().clear();
const symbolParagraph = new aspose.slides.Paragraph();
symbolParagraph.setText("Welcome to Aspose.Slides");
symbolParagraph.getParagraphFormat().getBullet().setType(java.newByte(aspose.slides.BulletType.Symbol));
symbolParagraph.getParagraphFormat().getBullet().setChar(java.newChar(0x2022));
symbolParagraph.getParagraphFormat().setIndent(25);
symbolParagraph.getParagraphFormat().getBullet().getColor().setColorType(aspose.slides.ColorType.RGB);
symbolParagraph.getParagraphFormat().getBullet().getColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
symbolParagraph.getParagraphFormat().getBullet().setBulletHardColor(java.newByte(aspose.slides.NullableBool.True));
symbolParagraph.getParagraphFormat().getBullet().setHeight(100);
textFrame.getParagraphs().add(symbolParagraph);
const numberedParagraph = new aspose.slides.Paragraph();
numberedParagraph.setText("This is a numbered item");
numberedParagraph.getParagraphFormat().getBullet().setType(java.newByte(aspose.slides.BulletType.Numbered));
numberedParagraph.getParagraphFormat().getBullet().setNumberedBulletStyle(java.newByte(aspose.slides.NumberedBulletStyle.BulletCircleNumWDBlackPlain));
numberedParagraph.getParagraphFormat().setIndent(25);
numberedParagraph.getParagraphFormat().getBullet().getColor().setColorType(aspose.slides.ColorType.RGB);
numberedParagraph.getParagraphFormat().getBullet().getColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
numberedParagraph.getParagraphFormat().getBullet().setBulletHardColor(java.newByte(aspose.slides.NullableBool.True));
numberedParagraph.getParagraphFormat().getBullet().setHeight(100);
textFrame.getParagraphs().add(numberedParagraph);
presentation.save("bulleted_and_numbered_list.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
استخدام نقاط صورة
تتيح لك نقاط الصورة استخدام صورة مخصصة بدلاً من الرمز أو الرقم.
- إنشاء مثال من الفئة Presentation.
- الوصول إلى الشريحة المطلوبة عبر فهرسها.
- إضافة AutoShape والوصول إلى TextFrame الخاص به.
- إزالة الفقرة الافتراضية من إطار النص.
- تحميل صورة النقطة وإضافتها إلى مجموعة صور العرض التقديمي كـ PPImage.
- إنشاء Paragraph وتعيين نصها.
- تعيين BulletFormat.setType إلى BulletType.Picture.
- إسناد الصورة عبر BulletFormat.getPicture وتعيين ارتفاع النقطة.
- إضافة الفقرة إلى إطار النص.
- حفظ العرض التقديمي المعدل.
هذا المثال بلغة JavaScript ينشئ نقطة صورة:
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const bulletImage = aspose.slides.Images.fromFile("image.png");
let presentationImage;
try {
presentationImage = presentation.getImages().addImage(bulletImage);
} finally {
bulletImage.dispose();
}
const shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 200, 200, 400, 200);
const textFrame = shape.getTextFrame();
textFrame.getParagraphs().clear();
const paragraph = new aspose.slides.Paragraph();
paragraph.setText("Welcome to Aspose.Slides");
paragraph.getParagraphFormat().getBullet().setType(java.newByte(aspose.slides.BulletType.Picture));
paragraph.getParagraphFormat().getBullet().getPicture().setImage(presentationImage);
paragraph.getParagraphFormat().getBullet().setHeight(100);
textFrame.getParagraphs().add(paragraph);
presentation.save("picture_bullet.pptx", aspose.slides.SaveFormat.Pptx);
presentation.save("picture_bullet.ppt", aspose.slides.SaveFormat.Ppt);
} finally {
presentation.dispose();
}
إنشاء قائمة متعددة المستويات
تعيين ParagraphFormat.setDepth لوضع الفقرات في مستويات مختلفة من القائمة. المستوى الأعلى له عمق 0.
- إنشاء Presentation والوصول إلى شريحة.
- إضافة AutoShape ومسح الفقرة الافتراضية من إطار النص الخاص به.
- إنشاء أربع فقرات وتكوين رموز النقاط الخاصة بها.
- تعيين قيم ParagraphFormat.setDepth إلى
0،1،2، و3. - إضافة الفقرات إلى إطار النص وحفظ العرض التقديمي.
هذا المثال بلغة JavaScript ينشئ قائمة نقطية بأربع مستويات:
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 200, 200, 400, 200);
const textFrame = shape.getTextFrame();
textFrame.getParagraphs().clear();
const firstParagraph = new aspose.slides.Paragraph();
firstParagraph.setText("Content");
firstParagraph.getParagraphFormat().getBullet().setType(java.newByte(aspose.slides.BulletType.Symbol));
firstParagraph.getParagraphFormat().getBullet().setChar(java.newChar(0x2022));
firstParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
firstParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
firstParagraph.getParagraphFormat().setDepth(java.newShort(0));
const secondParagraph = new aspose.slides.Paragraph();
secondParagraph.setText("Second level");
secondParagraph.getParagraphFormat().getBullet().setType(java.newByte(aspose.slides.BulletType.Symbol));
secondParagraph.getParagraphFormat().getBullet().setChar(java.newChar(45));
secondParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
secondParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
secondParagraph.getParagraphFormat().setDepth(java.newShort(1));
const thirdParagraph = new aspose.slides.Paragraph();
thirdParagraph.setText("Third level");
thirdParagraph.getParagraphFormat().getBullet().setType(java.newByte(aspose.slides.BulletType.Symbol));
thirdParagraph.getParagraphFormat().getBullet().setChar(java.newChar(0x2022));
thirdParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
thirdParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
thirdParagraph.getParagraphFormat().setDepth(java.newShort(2));
const fourthParagraph = new aspose.slides.Paragraph();
fourthParagraph.setText("Fourth level");
fourthParagraph.getParagraphFormat().getBullet().setType(java.newByte(aspose.slides.BulletType.Symbol));
fourthParagraph.getParagraphFormat().getBullet().setChar(java.newChar(45));
fourthParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
fourthParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
fourthParagraph.getParagraphFormat().setDepth(java.newShort(3));
textFrame.getParagraphs().add(firstParagraph);
textFrame.getParagraphs().add(secondParagraph);
textFrame.getParagraphs().add(thirdParagraph);
textFrame.getParagraphs().add(fourthParagraph);
presentation.save("multilevel_list.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
بدء عناصر القائمة الرقمية بقيم مخصصة
استخدام BulletFormat.setNumberedBulletStartWith لتعيين الرقم الأول المعروض لفقرة رقمية.
- إنشاء Presentation وإضافة AutoShape إلى شريحة.
- مسح الفقرة الافتراضية من إطار النص الخاص بالشكل.
- إنشاء ثلاث فقرات رقمية.
- تعيين BulletFormat.setNumberedBulletStartWith إلى
2،3، و7للفقرات ذات الصلة. - إضافة الفقرات إلى إطار النص وحفظ العرض التقديمي.
هذا المثال بلغة JavaScript يعين رقم بدء مخصص لكل فقرة:
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 200, 200, 400, 200);
const textFrame = shape.getTextFrame();
textFrame.getParagraphs().clear();
const firstParagraph = new aspose.slides.Paragraph();
firstParagraph.setText("Start at 2");
firstParagraph.getParagraphFormat().getBullet().setType(java.newByte(aspose.slides.BulletType.Numbered));
firstParagraph.getParagraphFormat().getBullet().setNumberedBulletStartWith(java.newShort(2));
textFrame.getParagraphs().add(firstParagraph);
const secondParagraph = new aspose.slides.Paragraph();
secondParagraph.setText("Start at 3");
secondParagraph.getParagraphFormat().getBullet().setType(java.newByte(aspose.slides.BulletType.Numbered));
secondParagraph.getParagraphFormat().getBullet().setNumberedBulletStartWith(java.newShort(3));
textFrame.getParagraphs().add(secondParagraph);
const thirdParagraph = new aspose.slides.Paragraph();
thirdParagraph.setText("Start at 7");
thirdParagraph.getParagraphFormat().getBullet().setType(java.newByte(aspose.slides.BulletType.Numbered));
thirdParagraph.getParagraphFormat().getBullet().setNumberedBulletStartWith(java.newShort(7));
textFrame.getParagraphs().add(thirdParagraph);
presentation.save("custom_numbered_list.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
التحكم في تخطيط الفقرة وخصائص النهاية
تعيين مسافة بادئة للسطر الأول
استخدام ParagraphFormat.setIndent للتحكم في مسافة البادئة للسطر الأول من الفقرة. هذه الطريقة تحرك السطر الأول فقط بالنسبة لهامش الفقرة الأيسر. القيمة الموجبة تحرك السطر الأول إلى اليمين، بينما تبقى بقية الأسطر محاذاة إلى جسم الفقرة.
استخدام ParagraphFormat.setMarginLeft عندما تحتاج إلى تحريك الفقرة بأكملها. استخدم ParagraphFormat.setIndent عندما تحتاج إلى تحريك السطر الأول فقط.
المثال أدناه ينشئ عدة فقرات ويطبق قيم مختلفة من ParagraphFormat.setIndent لتوضيح تأثير مسافة البادئة للسطر الأول على تخطيط الفقرة.
- إنشاء مثال من الفئة Presentation.
- الوصول إلى الشريحة المستهدفة.
- إضافة AutoShape مستطيلة إلى الشريحة.
- الوصول إلى TextFrame الخاص بالشكل ومسح الفقرة الافتراضية.
- إنشاء عدة فقرات وتعيين قيم مختلفة من ParagraphFormat.setIndent لها.
- إضافة الفقرات إلى إطار النص.
- حفظ العرض التقديمي المعدل.
هذا الكود يوضح كيفية تعيين مسافة بادئة للفقرة:
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 50, 420, 220);
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
shape.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
shape.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "GRAY"));
const textFrame = shape.getTextFrame();
textFrame.getTextFrameFormat().setAutofitType(java.newByte(aspose.slides.TextAutofitType.Shape));
textFrame.getParagraphs().clear();
const firstParagraph = new aspose.slides.Paragraph();
firstParagraph.setText("No first-line indent. Wrapped lines start at the same position as the first line.");
firstParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
firstParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
firstParagraph.getParagraphFormat().setMarginLeft(20);
firstParagraph.getParagraphFormat().setIndent(0);
const secondParagraph = new aspose.slides.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(java.newByte(aspose.slides.FillType.Solid));
secondParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
secondParagraph.getParagraphFormat().setMarginLeft(20);
secondParagraph.getParagraphFormat().setIndent(20);
const thirdParagraph = new aspose.slides.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(java.newByte(aspose.slides.FillType.Solid));
thirdParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
thirdParagraph.getParagraphFormat().setMarginLeft(20);
thirdParagraph.getParagraphFormat().setIndent(40);
textFrame.getParagraphs().add(firstParagraph);
textFrame.getParagraphs().add(secondParagraph);
textFrame.getParagraphs().add(thirdParagraph);
presentation.save("paragraph_indent.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

تعيين مسافة بادئة معلقة
المسافة البادئة المعلقة هي تخطيط للفقرة بحيث يبدأ السطر الأول إلى اليسار من باقي الأسطر. في Aspose.Slides، يمكنك إنشاء هذا التأثير باستخدام ParagraphFormat.setIndent. مرّر قيمة سلبية لتحريك السطر الأول إلى اليسار بالنسبة إلى جسم الفقرة.
في الممارسة العملية، يحدد ParagraphFormat.setMarginLeft الموقع الأيسر لجسم الفقرة، ويحدد ParagraphFormat.setIndent موقع السطر الأول بالنسبة إلى ذلك الهامش. لإنشاء مسافة بادئة معلقة، مرّر قيمة موجبة إلى setMarginLeft وقيمة سلبية إلى setIndent.
هذا التنسيق مفيد للمراجع الببليوجرافية، المراجع، مدخلات القاموس، وغيرها من الفقرات التي يجب أن تكون الأسطر المتعبة محاذية تحت جسم الفقرة بدلاً من الحرف الأول للسطر الأول.
- إنشاء مثال من الفئة Presentation.
- الوصول إلى الشريحة المستهدفة.
- إضافة AutoShape مستطيلة إلى الشريحة.
- الوصول إلى TextFrame الخاص بالشكل ومسح الفقرة الافتراضية.
- إنشاء فقرات وتمرير قيمة موجبة إلى ParagraphFormat.setMarginLeft لكل فقرة.
- تمرير قيمة سلبية إلى ParagraphFormat.setIndent لإنشاء تأثير المسافة البادئة المعلقة.
- إضافة الفقرات إلى إطار النص.
- حفظ العرض التقديمي المعدل.
هذا الكود يوضح كيفية تعيين مسافة بادئة معلقة لفقرة:
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 50, 420, 220);
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
shape.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
shape.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "GRAY"));
const textFrame = shape.getTextFrame();
textFrame.getTextFrameFormat().setAutofitType(java.newByte(aspose.slides.TextAutofitType.Shape));
textFrame.getParagraphs().clear();
const firstParagraph = new aspose.slides.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(java.newByte(aspose.slides.FillType.Solid));
firstParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
firstParagraph.getParagraphFormat().setMarginLeft(40);
firstParagraph.getParagraphFormat().setIndent(-20);
const secondParagraph = new aspose.slides.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(java.newByte(aspose.slides.FillType.Solid));
secondParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
secondParagraph.getParagraphFormat().setMarginLeft(60);
secondParagraph.getParagraphFormat().setIndent(-30);
textFrame.getParagraphs().add(firstParagraph);
textFrame.getParagraphs().add(secondParagraph);
presentation.save("hanging_indent.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

تعيين خصائص نهاية الفقرة
Paragraph.setEndParagraphPortionFormat يتحكم في تنسيق علامة نهاية الفقرة. المثال التالي يعيّن حجم الخط وخط اللاتينية لعلامة نهاية الفقرة الثانية:
- إنشاء أو تحميل Presentation والوصول إلى شريحة.
- إضافة AutoShape ومسح الفقرة الافتراضية الخاصة به.
- إنشاء فقرتين وإضافة أقسام نصية إليهما.
- إنشاء PortionFormat لعلامة نهاية الفقرة الثانية.
- تعيين BasePortionFormat.setFontHeight و BasePortionFormat.setLatinFont.
- إسناد التنسيق عبر Paragraph.setEndParagraphPortionFormat وحفظ العرض التقديمي.
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 10, 10, 200, 250);
const textFrame = shape.getTextFrame();
textFrame.getParagraphs().clear();
const firstParagraph = new aspose.slides.Paragraph();
firstParagraph.getPortions().add(new aspose.slides.Portion("Sample text"));
const secondParagraph = new aspose.slides.Paragraph();
secondParagraph.getPortions().add(new aspose.slides.Portion("Sample text 2"));
const endParagraphFormat = new aspose.slides.PortionFormat();
endParagraphFormat.setFontHeight(48);
endParagraphFormat.setLatinFont(new aspose.slides.FontData("Times New Roman"));
secondParagraph.setEndParagraphPortionFormat(endParagraphFormat);
textFrame.getParagraphs().add(firstParagraph);
textFrame.getParagraphs().add(secondParagraph);
presentation.save("end_paragraph_format.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
استيراد وتصدير محتوى الفقرة
استيراد نص HTML إلى الفقرات
استخدام ParagraphCollection.addFromHtml لتحويل ترميز HTML إلى فقرات وأقسام داخل إطار نص.
- إنشاء مثال من الفئة Presentation.
- الوصول إلى شريحة وإضافة AutoShape.
- الوصول إلى TextFrame الخاص بالشكل ومسح الفقرة الافتراضية.
- تعريف أو قراءة سلسلة HTML المصدر.
- تمرير سلسلة HTML إلى ParagraphCollection.addFromHtml.
- حفظ العرض التقديمي المعدل.
هذا المثال بلغة JavaScript يستورد HTML إلى إطار نص:
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const shapeWidth = presentation.getSlideSize().getSize().getWidth() - 20;
const shapeHeight = presentation.getSlideSize().getSize().getHeight() - 20;
const shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 10, 10, shapeWidth, shapeHeight);
shape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
shape.getTextFrame().getParagraphs().clear();
const html = "<p><b>Aspose.Slides</b> imports HTML text into presentation paragraphs.</p>";
shape.getTextFrame().getParagraphs().addFromHtml(html);
presentation.save("html_text.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
تصدير نص الفقرة إلى HTML
استخدام ParagraphCollection.exportToHtml لتصدير مجموعة محددة من الفقرات كملف HTML.
- إنشاء أو تحميل مثال من الفئة Presentation.
- الوصول إلى الشريحة والعثور على AutoShape الذي يحتوي على النص.
- الوصول إلى TextFrame الخاص بالشكل.
- استدعاء ParagraphCollection.exportToHtml مع فهرس الفقرة البداية وعدد الفقرات المراد تصديرها.
- كتابة سلسلة HTML المسترجعة إلى ملف.
هذا المثال المستقل بلغة JavaScript ينشئ شكل نص ويصدر جميع فقراته:
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
const fs = require("fs");
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const sourceShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 20, 20, 400, 100);
const sourceTextFrame = sourceShape.getTextFrame();
sourceTextFrame.getParagraphs().clear();
for (const text of ["First paragraph", "Second paragraph", "Third paragraph"]) {
const sourceParagraph = new aspose.slides.Paragraph();
sourceParagraph.setText(text);
sourceTextFrame.getParagraphs().add(sourceParagraph);
}
const shape = slide.getShapes().get_Item(0);
if (java.instanceOf(shape, "com.aspose.slides.IAutoShape")) {
const textFrame = shape.getTextFrame();
if (textFrame !== null) {
const paragraphs = textFrame.getParagraphs();
const html = paragraphs.exportToHtml(0, paragraphs.getCount(), null);
fs.writeFileSync("paragraphs.html", html, "utf8");
} else {
console.log("The first shape does not contain a text frame.");
}
} else {
console.log("The first shape is not a text shape.");
}
} finally {
presentation.dispose();
}
عرض الفقرة كصورة
Paragraph.getImage يعرض فقرة فردية مباشرة ويعيد كائنًا من نوع IImage. احفظ النتيجة إلى ملف باستخدام IImage.save. لا تحتاج إلى عرض الشكل الحاوي أو قص صورة bitmap يدويًا.
Paragraph.getImage يمكن أن تُعيد null إذا لم يتم العثور على الفقرة في مجموعتها الأم، أو لا تملك حدود رسم صالحة، أو لا يمكن رسمها. تحقق من النتيجة قبل حفظها وتأكد من التخلص من الصورة المسترجعة بعد الاستخدام.
عرض الفقرة بالمقياس الافتراضي
صندوق النص التالي يحتوي على ثلاث فقرات:

المثال التالي يعرض الفقرة الثانية في شكل نص عادي بالمقياس الافتراضي ويحفظ الصورة المسترجعة بتنسيق PNG. يضمن القسم finally التخلص الصحيح من الصورة.
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const sourceShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 20, 20, 400, 100);
const sourceTextFrame = sourceShape.getTextFrame();
sourceTextFrame.getParagraphs().clear();
for (const text of ["First paragraph", "Second paragraph", "Third paragraph"]) {
const sourceParagraph = new aspose.slides.Paragraph();
sourceParagraph.setText(text);
sourceTextFrame.getParagraphs().add(sourceParagraph);
}
const shape = slide.getShapes().get_Item(0);
if (java.instanceOf(shape, "com.aspose.slides.IAutoShape")) {
const textFrame = shape.getTextFrame();
if (textFrame !== null && textFrame.getParagraphs().getCount() > 1) {
const paragraph = textFrame.getParagraphs().get_Item(1);
const paragraphImage = paragraph.getImage();
if (paragraphImage !== null) {
try {
paragraphImage.save("paragraph.png", aspose.slides.ImageFormat.Png);
} finally {
paragraphImage.dispose();
}
} else {
console.log("The paragraph could not be rendered.");
}
} else {
console.log("The expected paragraph was not found.");
}
} else {
console.log("The first shape is not a text shape.");
}
} finally {
presentation.dispose();
}
النتيجة:

عرض الفقرة في خلية جدول مع تكبير
استخدام نسخة Paragraph.getImage التي تقبل معاملات scaleX و scaleY لتحديد عوامل التكبير الأفقي والعمودي. المثال التالي ينشئ جدولًا، يعرض الفقرة في خليةه الأولى بعرض وارتفاع ضعفين عن الافتراضي، ويحفظ النتيجة كصورة PNG.
var aspose = aspose || {};
aspose.slides = require("aspose.slides.via.java");
const java = require("java");
const scaleX = 2;
const scaleY = 2;
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const columnWidths = java.newArray("double", [300]);
const rowHeights = java.newArray("double", [80]);
const table = slide.getShapes().addTable(50, 50, columnWidths, rowHeights);
const paragraph = table.get_Item(0, 0).getTextFrame().getParagraphs().get_Item(0);
paragraph.setText("Text in a table cell");
const paragraphImage = paragraph.getImage(scaleX, scaleY);
if (paragraphImage !== null) {
try {
paragraphImage.save("table_paragraph.png", aspose.slides.ImageFormat.Png);
} finally {
paragraphImage.dispose();
}
} else {
console.log("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 للأقسام الفردية، بحيث يمكن لفقرة واحدة أن تحتوي نصًا بعدة لغات.