Java REST API를 사용하여 PowerPoint에 하이퍼링크를 추가하는 방법에 대한 이 가이드를 따르세요. 프레젠테이션 작업을 위한 모든 고급 기능을 지원하는 Java 기반 Cloud SDK를 사용하여 Java RESTful Service로 PowerPoint에 하이퍼링크를 자동으로 삽입하는 방법을 배우게 됩니다. 사용자 정의 하이퍼링크를 추가하기 위해 특정 슬라이드와 모양을 선택하는 데 도움이 됩니다.
전제조건
다운로드 Aspose.Slides Cloud SDK for Java for inserting hyperlinks
도형에 링크를 추가하려면 위 SDK로 Java 프로젝트를 설정하세요.
Java 기반 API를 사용하여 PowerPoint에 링크를 추가하는 단계
- 인증을 위해 API 키와 비밀번호를 사용하여 SlidesApi를 인스턴스화합니다.
- 입력 파일을 메모리 스트림으로 읽고 업로드합니다.
- 하이퍼링크 추가를 위한 슬라이드 및 도형의 인덱스 설정(1 기반 인덱스)
- 하이퍼링크가 있는 모양 개체 만들기
- Update 하이퍼링크가 있는 지정된 슬라이드의 도형
- 확인을 위해 업데이트된 하이퍼링크의 URL을 콘솔에 인쇄합니다.
- 업데이트된 프레젠테이션을 클라우드에서 스트림으로 다운로드하고 디스크에 저장하세요.
이 단계에서는 Java REST API를 사용하여 PowerPoint에 하이퍼링크를 추가하는 방법을 설명합니다. 동작 유형과 외부 URL을 정의하여 Shape를 생성하고 하이퍼링크를 추가할 수 있습니다. 마지막으로 새로 생성된 모양을 사용하여 원하는 슬라이드의 대상 모양을 업데이트하고 필요한 경우 출력을 디스크에 저장합니다.
Java Low Code API를 사용하여 PowerPoint에 링크를 삽입하는 코드
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); | |
} | |
} |
이 코드는 Java REST 인터페이스를 사용하여 PowerPoint에 하이퍼링크를 삽입하는 방법을 보여줍니다. 하이퍼링크, 도구 설명, 기록, 강조 표시 클릭 및 클릭 시 사운드 중지를 활성화/비활성화하는 플래그와 같은 하이퍼링크의 다양한 속성을 설정할 수 있습니다. 이러한 모든 속성은 하이퍼링크를 클릭하는 대신 하이퍼링크 위로 마우스를 가져가면 사용할 수 있습니다.
이 기사에서는 Java Low Code API*를 사용하여 PowerPoint에서 *하이퍼링크를 만드는 방법을 설명했습니다. 슬라이드에 SmartArt를 추가하려면 Java REST API를 사용하여 PowerPoint에 SmartArt 추가의 문서를 참조하세요.