Vadovaukitės šiuo vadovu, kaip pridėti hipersaitą prie PowerPoint naudojant Java REST API. Išmoksite automatiškai įterpti hipersaitą į PowerPoint naudodami Java RESTful Service naudodami Java pagrįstą debesies SDK, palaikantį visas išplėstines darbo su pristatymais funkcijas. Tai padės jums pasirinkti tam tikrą skaidrę ir formą, kad galėtumėte pridėti pasirinktinį hipersaitą.
Būtina sąlyga
Atsisiųsti Aspose.Slides Cloud SDK for Java for inserting hyperlinks
Nustatykite „Java“ projektą naudodami aukščiau pateiktą SDK, kad pridėtumėte nuorodą į formą
Veiksmai, kaip pridėti nuorodą į „PowerPoint“ naudojant „Java“ pagrįstą API
- Sukurkite SlidesApi naudodami API raktą ir autentifikavimo paslaptį
- Perskaitykite įvesties failą į atminties srautą ir įkelkite jį
- Nustatyti skaidrių ir formų indeksus, kad būtų galima pridėti hipersaitą (1 indeksas)
- Sukurkite formos objektą su hipersaitu
- Update figūrą nurodytoje skaidrėje su hipersaitu
- Atspausdinkite atnaujintą hipersaito URL į konsolę, kad patikrintumėte
- Atsisiųskite atnaujintą pristatymą iš debesies kaip srautą ir išsaugokite jį diske
Šie veiksmai paaiškina kaip pridėti hipersaitą PowerPoint naudojant Java REST API. Galite sukurti figūrą ir pridėti hipersaitą, nurodydami veiksmo tipą ir išorinį URL. Galiausiai atnaujinkite tikslinę formą norimoje skaidrėje naudodami naujai sukurtą formą ir, jei reikia, išsaugokite išvestį diske.
Kodas nuorodai įterpti į PowerPoint su 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); | |
} | |
} |
Šis kodas parodo kaip įterpti hipersaitą į PowerPoint naudojant Java REST sąsają. Galite nustatyti įvairias hipersaito ypatybes, pvz., vėliavėlę, kad įjungtumėte / išjungtumėte hipersaitą, patarimą, istoriją, paryškintumėte spustelėjimą ir sustabdytumėte garsą spustelėjus. Atminkite, kad visos šios savybės pasiekiamos užvedus pelės žymeklį virš hipersaito, o ne jį spustelėjus.
Šis straipsnis mus išmokė sukurti hipersaitą programoje PowerPoint naudojant Java Low Code API. Norėdami skaidrėje pridėti SmartArt, žr. straipsnį Pridėkite SmartArt prie PowerPoint naudodami Java REST API.