Այս հոդվածը ցույց է տալիս, թե ինչպես փոխակերպել HTML-ը PowerPoint-ի Java REST API-ի միջոցով: Դուք կսովորեք ավտոմատ կերպով ներդնել HTML-ը PowerPoint-ում Java REST ինտերֆեյսի միջոցով՝ օգտագործելով Java-ի վրա հիմնված Cloud SDK-ն: Այն կիսում է առկա ներկայացմանը HTML ավելացնելու կամ ամպային պահեստում նոր ներկայացում ստեղծելու մանրամասները:
Նախապայման
[Ստեղծեք հաշվի API հավատարմագրեր] ( https://kb.aspose.cloud/ hy/total/java/how-to-create-aspose-cloud-apis-account/)
Բեռնել Aspose.Slides Cloud SDK for Java to convert HTML to a presentation
Կարգավորեք Java նախագիծը վերը նշված SDK-ով` շնորհանդեսում HTML-ի հետ աշխատելու համար
Java Low Code API-ով HTML-ը PowerPoint-ի վերածելու քայլեր
- Կարգավորեք SlidesApi օբյեկտը` սահմանելով Client ID-ն և գաղտնիքը HTML-ի օգտագործման համար
- Նախաձեռնեք HTML սկրիպտը, որը ցանկանում եք վերափոխել ներկայացման
- Զանգահարեք ImportFromHtml մեթոդը՝ վերը նշված HTML-ով առցանց ներկայացում ստեղծելու համար
- Ներբեռնեք և պահեք նոր ստեղծված ներկայացումը սկավառակի վրա
Այս քայլերը նկարագրում են, թե ինչպես ներդնել HTML-ը PowerPoint-ում Java REST ինտերֆեյսի միջոցով: Ստեղծեք SlidesApi օբյեկտը, սահմանեք HTML սցենարը տողի մեջ և զանգահարեք ImportFromHtml() մեթոդը՝ HTML սկրիպտը ներկայացման փոխակերպելու համար: Եթե ներկայացումը առցանց գոյություն չունի, այն կստեղծվի տվյալ անունով, հակառակ դեպքում կարող եք վերբեռնել ներկայացումը և այնուհետև օգտագործել դրա անունը՝ HTML բովանդակությամբ սլայդ ավելացնելու համար:
Java REST API-ով HTML PowerPoint ներկայացում ստեղծելու կոդ
package KbExamples; | |
import com.aspose.slides.ApiException; | |
import com.aspose.slides.api.SlidesApi; | |
import com.aspose.slides.model.Document; | |
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_HtmlToPresentation { | |
protected static SlidesApi presentationApi; | |
public Example_HtmlToPresentation() { | |
if (presentationApi == null) { | |
presentationApi = new SlidesApi("appSid", "appKey"); | |
} | |
} | |
public void insertHtmlText() throws ApiException, IOException { | |
String localPath = "/home/downloads/"; | |
String fileName = "Sample.pptx"; | |
String outputFileName = "Output.pptx"; | |
String storageFolderName = "TempTests"; | |
String html = """ | |
<html> | |
<head> | |
<style> | |
table { | |
font-family: arial, sans-serif; | |
border-collapse: collapse; | |
width: 100%; | |
} | |
td, th { | |
border: 1px solid #dddddd; | |
text-align: left; | |
padding: 8px; | |
} | |
tr:nth-child(even) { | |
background-color: #dddddd; | |
} | |
</style> | |
</head> | |
<body> | |
<h2>HTML Table</h2> | |
<table> | |
<thead> | |
<tr> | |
<th>Roll No</th> | |
<th>Name</th> | |
<th>Age</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td>1</td> | |
<td>John Doe</td> | |
<td>10</td> | |
</tr> | |
<tr> | |
<td>2</td> | |
<td>Jane Smith</td> | |
<td>9</td> | |
</tr> | |
</tbody> | |
</table> | |
</body> | |
</html> | |
"""; | |
Document response = presentationApi.importFromHtml(fileName, html, null, null, storageFolderName); | |
System.out.println(response.getSelfUri().getHref()); | |
File presentationFile = presentationApi.downloadFile(storageFolderName+"/"+fileName, null, null); | |
// Copy the downloaded presentation with inserted HTML text to the local directory | |
copyFile(presentationFile, new File(localPath, outputFileName)); | |
System.out.println("Presentation with imported HTML text 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 Low Code API-ով * HTML ավելացնելու գործընթացը PowerPoint-ում: Դուք կարող եք օգտագործել HTML տողը որոշ արտաքին աղբյուրից, օրինակ՝ տվյալների բազայից կամ սկավառակի վրա գտնվող որևէ ֆայլից: Եթե դուք օգտագործում եք գոյություն ունեցող ներկայացում, ImportFromHtml() մեթոդը կստեղծի նոր սլայդ տվյալ HTML բովանդակությամբ:
Այս հոդվածը մեզ առաջնորդել է HTML սկրիպտը որպես սլայդի բովանդակություն օգտագործելու հարցում: Ներկայացման մեջ տեքստը ընդգծելու համար տես Ընդգծեք տեքստը PowerPoint-ում Java REST API-ով-ի հոդվածը: