Օգտագործեք նկարը որպես ֆոն PowerPoint-ում Java REST API-ով

Հետևեք այս հոդվածին, որպեսզի օգտագործեք նկարը որպես ֆոն PowerPoint-ում Java REST API-ով: Դուք կսովորեք փոխել ֆոնային ձևավորումը PowerPoint-ում Java REST ինտերֆեյսի միջոցով Java-ի վրա հիմնված Cloud SDK-ի միջոցով: Տարբեր տարբերակներ են քննարկվում սլայդում ֆոնային պատկերը հարմարեցնելու համար:

Նախապայման

PowerPoint-ի նախապատմությունները Java Low Code API-ով սահմանելու քայլեր

  1. Ստեղծեք SlidesApi օբյեկտը սլայդի ֆոնը սահմանելու համար
  2. Վերբեռնեք աղբյուրի PowerPoint-ի շնորհանդեսը Ամպային պահեստում եզակի անունով
  3. Կարդացեք պատկերի ֆայլի տվյալները բայթային զանգվածի մեջ և փոխարկեք այն 64 բազային տողի
  4. Ստեղծեք SlideBackground օբյեկտը և սահմանեք լրացման ձևաչափը ֆոնային պատկերի պարամետրերը սահմանելու համար
  5. Զանգահարեք SetBackground() մեթոդը՝ PowerPoint սլայդի ֆոնը սահմանելու համար
  6. Ներբեռնեք թարմացված PowerPoint շնորհանդեսը նախապատմությունը դնելուց հետո

Այս քայլերը բացատրում են, թե ինչպես պետք է սահմանել ֆոն PowerPoint-ի ներկայացման համար Java-ի վրա հիմնված API-ով: Ստեղծեք SlidesApi օբյեկտը, վերբեռնեք ներկայացումը Cloud պահեստում, կարդացեք պատկերի տվյալները, փոխարկեք այն բազային 64 տողի և օգտագործեք այն SlideBackground օբյեկտում՝ FillFormat-ը կարգավորելու համար: Ի վերջո, զանգահարեք SetBackground() մեթոդը՝ պատկերը որպես ֆոն ավելացնելու և ելքային ֆայլը սկավառակի վրա ներբեռնելու համար։

Կոդ՝ Java Low Code API-ով PPT ֆոն ավելացնելու համար

import com.aspose.slides.ApiException;
import com.aspose.slides.api.SlidesApi;
import com.aspose.slides.model.PictureFill;
import com.aspose.slides.model.SlideBackground;
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.Base64;
public class Example_AddPresentationBackgroundImage {
protected static SlidesApi presentationApi;
public Example_AddPresentationBackgroundImage() {
if (presentationApi == null) {
presentationApi = new SlidesApi("appSid", "appKey");
}
}
public void addBackgroundImage() throws ApiException, IOException {
String localPath = "/home/downloads/";
String fileName = "Sample.pptx";
String imageFileName = "Background.png";
String storageFolderName = "TempTests";
presentationApi.uploadFile(storageFolderName+"/"+fileName, readFileToByteArray(localPath + fileName),null);
SlideBackground pictureBackground = new SlideBackground();
PictureFill pictureFill = new PictureFill();//For customization of the background image
pictureFill.setBase64Data(Base64.getEncoder().encodeToString(readFileToByteArray(localPath + imageFileName)));
pictureFill.setPictureFillMode(PictureFill.PictureFillModeEnum.STRETCH);
pictureBackground.setFillFormat(pictureFill);
// Set slide background image
SlideBackground currentBackground = presentationApi.setBackground(fileName, 1, pictureBackground, null, storageFolderName, null);
File presentationFile = presentationApi.downloadFile(storageFolderName+"/"+fileName, null, null);
// Copy the downloaded presentation with new background image to the local directory
copyFile(presentationFile, new File(localPath, fileName));
System.out.println("Presentation slide background image 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);
}
}

Այս կոդը ցույց է տվել, թե ինչպես կարելի է սահմանել ֆոնը ներկայացման սլայդի համար Java Low Code API-ով: Դուք կարող եք սահմանել պատկերի տարբեր հատկություններ, ներառյալ նկարի լրացման ռեժիմը, փայլը, ներքին ստվերը, արտաքին ստվերը, փափուկ եզրը և արտացոլումը: Տրամադրեք վերբեռնված PowerPoint ներկայացման գաղտնաբառը, եթե այն պաշտպանված է:

Այս հոդվածը մեզ սովորեցրել է սահմանել ֆոնային պատկերներ PPT-ի համար Java REST ինտերֆեյսով: Եթե ցանկանում եք պատճենել սլայդները ներկայացման կամ այլ ներկայացման մեջ, տես Պատճենել PowerPoint սլայդը Java REST API-ով հոդվածը:

 Հայերեն