اتبع هذا الدليل حول كيفية إضافة رابط تشعبي إلى PowerPoint باستخدام Java REST API. سوف تتعلم كيفية إدراج الارتباط التشعبي في PowerPoint تلقائيًا باستخدام Java RESTful Service باستخدام Cloud SDK المستند إلى Java والذي يدعم جميع الميزات المتقدمة للعمل مع العروض التقديمية. سيساعدك ذلك في تحديد شريحة وشكل معين لإضافة ارتباط تشعبي مخصص.
** المتطلب السابق **
تحميل Aspose.Slides Cloud SDK for Java for inserting hyperlinks
إعداد مشروع Java باستخدام SDK أعلاه لإضافة رابط إلى الشكل
خطوات إضافة رابط إلى PowerPoint باستخدام واجهة برمجة التطبيقات المستندة إلى Java
- قم بإنشاء مثيل SlidesApi باستخدام مفتاح API وسر المصادقة
- اقرأ ملف الإدخال في دفق الذاكرة وقم بتحميله
- تعيين فهارس الشرائح والأشكال لإضافة ارتباط تشعبي (فهرس يعتمد على 1)
- إنشاء كائن شكل مع ارتباط تشعبي
- Update الشكل الموجود على الشريحة المحددة مع الارتباط التشعبي
- قم بطباعة عنوان URL للارتباط التشعبي المحدث إلى وحدة التحكم للتحقق منه
- قم بتنزيل العرض التقديمي المحدث من السحابة كدفق واحفظه على القرص
تشرح هذه الخطوات كيفية إضافة ارتباط تشعبي في PowerPoint باستخدام Java REST API. يمكنك إنشاء شكل وإضافة ارتباط تشعبي عن طريق تحديد نوع الإجراء وعنوان URL الخارجي. وأخيرًا، قم بتحديث الشكل المستهدف في الشريحة المطلوبة باستخدام الشكل الذي تم إنشاؤه حديثًا واحفظ المخرجات على القرص إذا لزم الأمر.
رمز لإدراج رابط في PowerPoint باستخدام Java Low Code 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; | |
public class Example_AddHyperlinkInPresentation { | |
protected static SlidesApi presentationApi; | |
public Example_AddHyperlinkInPresentation() { | |
if (presentationApi == null) { | |
presentationApi = new SlidesApi("appSid", "appKey"); | |
} | |
} | |
public void addHyperlinkInSlide() throws ApiException, IOException { | |
String localPath = "/home/downloads/"; | |
String fileName = "PresentationWithHyperlink.pptx"; | |
String storageFolderName = "TempTests"; | |
// Index of the slide and shape where the target shape is located (1-based index). | |
int slideIndex = 2, shapeIndex = 2; | |
Shape shape = new Shape(); // Create a shape object with a hyperlink | |
Hyperlink hyperlink = new Hyperlink(); | |
hyperlink.setActionType(Hyperlink.ActionTypeEnum.HYPERLINK);// Set the action type as a hyperlink. | |
hyperlink.setExternalUrl("https://docs.aspose.cloud/slides"); // The URL for the hyperlink. | |
shape.setHyperlinkClick(hyperlink); | |
// Update the shape on the specified slide with the hyperlink | |
ShapeBase updatedShpWithHyperlink = presentationApi.updateShape(fileName, slideIndex, shapeIndex, shape, | |
null, storageFolderName, null, null); | |
// Print the updated hyperlink's URL to the console for verification. | |
System.out.println(updatedShpWithHyperlink.getHyperlinkClick().getExternalUrl()); | |
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 image 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); | |
} | |
} |
يوضح هذا الرمز كيفية إدراج ارتباط تشعبي في PowerPoint باستخدام واجهة Java REST. يمكنك تعيين خصائص مختلفة للارتباط التشعبي مثل علامة لتمكين/تعطيل الارتباط التشعبي وتلميح الأدوات والمحفوظات والنقر المميز وإيقاف الصوت عند النقر. لاحظ أن كافة هذه الخصائص متوفرة عن طريق المرور فوق الارتباط التشعبي بدلاً من النقر فوقه.
علمتنا هذه المقالة كيفية إنشاء ارتباط تشعبي في PowerPoint باستخدام Java Low Code API. لإضافة SmartArt في شريحة، راجع المقالة الموجودة على أضف SmartArt إلى PowerPoint باستخدام Java REST API.