Java REST API ile PowerPoint bağlantısına nasıl köprü ekleneceğini öğrenmek için bu kılavuzu izleyin. Sunumlarla çalışmaya yönelik tüm gelişmiş özellikleri destekleyen Java tabanlı bir Bulut SDK kullanarak Java RESTful Hizmeti ile PowerPoint’e otomatik olarak köprü eklemeyi öğreneceksiniz. Özel bir köprü eklemek için belirli bir slayt ve şekli seçmenize yardımcı olacaktır.
Önkoşul
İndirmek Aspose.Slides Cloud SDK for Java for inserting hyperlinks
Bir şekle bağlantı eklemek için yukarıdaki SDK ile Java projesini kurun
Java Tabanlı API ile PowerPoint’e Bağlantı Ekleme Adımları
- Kimlik doğrulama için API anahtarı ve sırrıyla SlidesApi örneğini oluşturun
- Giriş dosyasını bir bellek akışına okuyun ve yükleyin
- Köprü eklemek için slaytların ve şekillerin dizinlerini ayarlayın (1 tabanlı dizin)
- Köprü içeren bir şekil nesnesi oluşturma
- Update belirtilen slaytta köprü içeren şekil
- Doğrulama için güncellenen köprünün URL’sini konsola yazdırın
- Güncellenen sunumu buluttan akış olarak indirin ve diske kaydedin
Bu adımlarda Java REST API ile PowerPoint’te köprünün nasıl ekleneceği açıklanmaktadır. Eylem türünü ve harici URL’yi tanımlayarak bir Şekil oluşturabilir ve köprü ekleyebilirsiniz. Son olarak, yeni oluşturulan şekli kullanarak istenen slayttaki hedef şekli güncelleyin ve gerekirse çıktıyı diske kaydedin.
Java Düşük Kod API’si ile PowerPoint’e Bağlantı Ekleme Kodu
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); | |
} | |
} |
Bu kod Java REST Arayüzü ile PowerPoint’te köprünün nasıl ekleneceğini gösterir. Köprüyü etkinleştirmek/devre dışı bırakmak için bayrak, araç ipucu, geçmiş, tıklamayı vurgulama ve tıklama sırasında sesi durdurma gibi köprünün çeşitli özelliklerini ayarlayabilirsiniz. Tüm bu özelliklere, köprüyü tıklatmak yerine üzerine gelindiğinde ulaşılabileceğini unutmayın.
Bu makale bize PowerPoint’te Java Low Code API* ile bir *köprü oluşturmayı öğretti. Slayta SmartArt eklemek için Java REST API ile SmartArt’ı PowerPoint’e ekleyin hakkındaki makaleye bakın.