توضح هذه المقالة كيفية إضافة SmartArt إلى PowerPoint باستخدام Java REST API. سوف تتعلم كيفية إدراج PowerPoint SmartArt مع Java Low Code API تلقائيًا باستخدام Cloud SDK المستندة إلى Java. تتم مناقشة مختلف الفئات والعدادين لإنشاء أنواع مختلفة من SmartArt في شريحة عرض PowerPoint التقديمي.
الشرط الأساسي
تحميل Aspose.Slides Cloud SDK for Java for inserting SmartArt in slides
إعداد مشروع Java باستخدام SDK أعلاه لإنشاء رسومات SmartArt
خطوات لإضافة عرض تقديمي لـ PowerPoint SmartArt باستخدام Java REST API
- قم بتعيين بيانات الاعتماد في كائن SlidesApi للعمل مع SmartArt
- قم بتحميل العرض التقديمي المصدر إلى وحدة التخزين السحابية لإدراج الرسومات الذكية
- قم بإنشاء بيانات رسومات عن طريق تعيين الخصائص المطلوبة في كائن SmartArt
- أدخل SmartArt باستخدام طريقة CreateShape().
- قم بتنزيل ملف العرض التقديمي المحدث بعد إضافة SmartArt إليه
تشرح هذه الخطوات كيفية العمل مع SmartArt for PowerPoint مع Java REST API. قم بإنشاء كائن فئة SlidesApi، وتحميل العرض التقديمي المصدر، وإنشاء كائن SmartArt بالإعدادات المحددة بما في ذلك الموضع والحجم والتخطيط والنمط السريع ونمط اللون. وأخيرًا، تتم إضافة عقد متعددة لـ SmartArt إلى الشريحة المعنية باستخدام طريقة CreateShape().
رمز لإضافة أشكال PowerPoint الذكية باستخدام Java Java-Based API
import com.aspose.slides.ApiException; | |
import com.aspose.slides.api.SlidesApi; | |
import com.aspose.slides.model.*; | |
import java.io.File; | |
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.StandardCopyOption; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class Example_AddSmartArtShapeInPresentation { | |
protected static SlidesApi presentationApi; | |
public Example_AddSmartArtShapeInPresentation() { | |
if (presentationApi == null) { | |
presentationApi = new SlidesApi("appSid", "appKey"); | |
} | |
} | |
public void addCustomShapeInSlide() throws ApiException, IOException { | |
String localPath = "/home/downloads/"; | |
String fileName = "Sample.pptx"; | |
String imageFileName = "ShapeImage.png"; | |
String storageFolderName = "TempTests"; | |
presentationApi.uploadFile(storageFolderName+"/"+fileName, readFileToByteArray(localPath + fileName),null); | |
// Configure SmartArt properties | |
SmartArt smartArt = new SmartArt(); | |
smartArt.setX(50.0); // Horizontal position of the SmartArt | |
smartArt.setY(50.0); // Horizontal position of the SmartArt | |
smartArt.setWidth(250.0); // Width of the SmartArt | |
smartArt.setHeight(250.0); // Height of the SmartArt | |
smartArt.setLayout(SmartArt.LayoutEnum.BENDINGPICTURESEMITRANSPARENTTEXT); // SmartArt layout | |
smartArt.setQuickStyle(SmartArt.QuickStyleEnum.SIMPLEFILL); // Quick style | |
smartArt.setColorStyle(SmartArt.ColorStyleEnum.COLOREDFILLACCENT1); // Color style | |
List<SmartArtNode> nodes = new ArrayList<SmartArtNode>(); | |
SmartArtNode node1 = new SmartArtNode(); | |
node1.setText("Planning"); | |
nodes.add(node1); | |
SmartArtNode node2 = new SmartArtNode(); | |
node2.setText("Design"); | |
nodes.add(node2); | |
SmartArtNode node3 = new SmartArtNode(); | |
node3.setText("Implementation"); | |
nodes.add(node3); | |
smartArt.setNodes(nodes); | |
// Add SmartArt to the first slide | |
ShapeBase addedSmartArt = presentationApi.createShape(fileName, 1, smartArt, null, null, null, storageFolderName, null, null ); | |
System.out.println("SmartArt added to the presentation successfully."); | |
File presentationFile = presentationApi.downloadFile(storageFolderName+"/"+fileName, null, null); | |
// Copy the downloaded presentation with new image shape to the local directory | |
copyFile(presentationFile, new File(localPath, fileName)); | |
System.out.println("Presentation slide with SmartArt shape is copied to: " + localPath + fileName); | |
} | |
public static byte[] readFileToByteArray(String filePath) throws IOException { | |
Path path = new File(filePath).toPath(); | |
return Files.readAllBytes(path); | |
} | |
private void copyFile(File sourceFile, File targetFile) throws IOException { | |
if (sourceFile == null || !sourceFile.exists()) { | |
throw new IOException("Source file does not exist: " + sourceFile); | |
} | |
// Ensure the target directory exists | |
Path targetPath = targetFile.toPath(); | |
Files.createDirectories(targetPath.getParent()); | |
// Copy the file | |
Files.copy(sourceFile.toPath(), targetPath, StandardCopyOption.REPLACE_EXISTING); | |
} | |
} |
يوضح هذا الرمز كيفية إدراج Smart Art graphics باستخدام Java REST Interface في الشريحة. استخدم LayoutEnum لتحديد شكل SmartArt المطلوب من قائمة كبيرة من القيم بما في ذلك AccentProcess، وAccentedPicture، وArrowRibbon، وBasicPyramid، وBasicProcess، وما إلى ذلك. وبالمثل، فإن عدادات النمط السريع ونمط الألوان لديها أيضًا مجموعة متنوعة من الخيارات لتخصيص SmartArt.
لقد علمتنا هذه المقالة كيفية إنشاء SmartArt في شريحة العرض التقديمي. لإضافة أشكال مخصصة في عرض تقديمي، راجع المقالة الموجودة على قم بإنشاء أشكال مخصصة في PowerPoint باستخدام Java REST API.