Следвайте тази статия, за да анимирате PowerPoint слайдове с Java REST API. Ще се научите да задавате преходи на слайдшоу с Java Low Code API с помощта на Java Cloud API. Ще се научите да модифицирате съществуваща PowerPoint презентация, като зададете различни ефекти на преход в желаните слайдове.
Предпоставка
Изтегляне Aspose.Slides Cloud SDK for Java for inserting transitions in the slides
Настройте Java проект с горния SDK, за да добавите анимация в слайд
Стъпки за добавяне на преход към слайд с Java REST API
- Задайте идентификационните данни за създаване на обект SlidesApi за добавяне на преходи
- Качете презентацията в облачното хранилище за добавяне на преходи
- Създайте нов слайд за настройка на прехода
- Създайте обект от класа SlideShowTransition за задаване на характеристики на прехода
- Задайте настройките за преход в обекта SlideShowTransition
- Извикайте метода UpdateSlide(), за да зададете преход на желания слайд
- Запазете изходната презентация с нови преходи
Тези стъпки описват процеса за добавяне на преходите на PowerPoint с Java REST интерфейс. Качете презентацията, създайте нов скид, добавете нов преходен обект към него и задайте желаните свойства в презентацията. Накрая извикайте UpdateSlide(), за да зададете новия преход към съществуващ слайд.
Код за добавяне на анимация и преход в PowerPoint с Java базиран API
import com.aspose.slides.ApiException; | |
import com.aspose.slides.api.SlidesApi; | |
import com.aspose.slides.model.SlideComment; | |
import com.aspose.slides.model.SlideCommentBase; | |
import com.aspose.slides.model.SlideComments; | |
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; | |
public class Example_AddSlideTransitionInPresentation { | |
protected static SlidesApi presentationApi; | |
public Example_AddSlideTransitionInPresentation() { | |
if (presentationApi == null) { | |
presentationApi = new SlidesApi("appSid", "appKey"); | |
} | |
} | |
public void addSlideTransition() throws ApiException, IOException { | |
String localPath = "/home/downloads/"; | |
String fileName = "Sample.pptx"; | |
String storageFolderName = "TempTests"; | |
presentationApi.uploadFile(storageFolderName+"/"+fileName, readFileToByteArray(localPath + fileName),null); | |
SlideComment comment = new SlideComment (); | |
comment.setText("Master comment here."); | |
comment.setAuthor("Mr. John"); | |
SlideComment subComment = new SlideComment (); | |
subComment.setText("Here is the sub-comment."); | |
subComment.setAuthor("Mr. Paul"); | |
ArrayList<SlideCommentBase> subComments = new ArrayList<SlideCommentBase>(); | |
subComments.add(subComment); | |
comment.childComments(subComments); | |
// Add slide comments | |
SlideComments comments = presentationApi.createComment(fileName, 2, comment, null, null, storageFolderName, null); | |
File presentationFile = presentationApi.downloadFile(storageFolderName+"/"+fileName, null, null); | |
// Copy the downloaded presentation with new comments to the local directory | |
copyFile(presentationFile, new File(localPath, fileName)); | |
System.out.println("Presentation slide comment is set and 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 API. Класът SlideShowTransition съдържа голям брой свойства като AdvanceAfter, AdvanceAfterTime, AdvanceOnClick, SoundMode, SoundName и др. Можете да използвате един и същ преход за множество слайдове, като извикате UpdateSlide() за всички желани слайдове.
Тази статия ни напътства да работим с преходи на презентации на PowerPoint с Java RESTful Service. За добавяне на раздели към слайд на презентация вижте статията на Добавете секции в PowerPoint с Java REST API.