We are going to discuss the details on how to insert webpage into PowerPoint using Java SDK. We do understand that PowerPoint to HTML is one of the popular scenarios where we need to export the PPT to HTML so that we can view the file in a web browser. But at the same time, we may have an existing PowerPoint and we may have a requirement of embedding HTML in PowerPoint or, for presentation purposes, we are interested to convert HTML to PPT.
PowerPoint Conversion SDK
We are going to use Aspose.Slides Cloud SDK for Java for conversion purposes. It’s a REST API offering the capabilities to create, edit and transform PowerPoint files to HTML, PDF, XPS, JPG, and various other Supported File Formats. At the same time, it also provides the feature to save HTML to PPT. Now please add the following details in pom.xml of your maven build project, so that SDK references are added to your project.
<repositories> <repository> <id>aspose-cloud</id> <name>artifact.aspose-cloud-releases</name> <url>http://artifact.aspose.cloud/repo</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.aspose</groupId> <artifactId>aspose-slides-cloud</artifactId> <version>22.4.0</version> </dependency> </dependencies>
After the installation, if you do not have an existing Cloud dashboard account, please create one by visiting Aspose.Cloud dashboard. If you have GitHub or Google account, simply Sign Up and obtain your client credentials.
Embedding HTML in PowerPoint using Java
This section explains how to read and insert Webpage into PowerPoint presentation. Please follow the steps specified below to accomplish the requirement. Once the operation is successful, the resultant file is stored in Cloud storage.
- Create an instance of SlidesApi while providing Client credentials as arguments
- Now create an instance of StringBuilder
- The next step is to read HTML file content into the BufferedReader object
- As the API expects input HTML is String format, so we need to convert loaded HTML content to String format using contentBuilder.toString(…) method
- Finally, call the importFromHtml(..) method for embedding HTML in PowerPoint.
Please note that if the PPT file is already available in cloud storage, so the API will insert webpage into PowerPoint
HTML to PPT using cURL Commands
Now we are going to discuss the conversion of HTML to PPT using cURL commands. So the first step is to generate a JWT access token based on your client credentials.
curl -v "https://api.aspose.cloud/connect/token" \ -X POST \ -d "grant_type=client_credentials&client_id=bbf94a2c-6d7e-4020-b4d2-b9809741374e&client_secret=1c9379bb7d701c26cc87e741a29987bb" \ -H "Content-Type: application/x-www-form-urlencoded" \ -H "Accept: application/json"
Once the JWT token is generated, we can execute the following command to convert provided HTML to PPT format and save the resultant PowerPoint in Cloud storage.
curl -v -X POST "https://api.aspose.cloud/v3.0/slides/Resultant.ppt/fromHtml" \ -H "accept: application/json" \ -H "authorization: Bearer <JWT Token>" \ -H "Content-Type: application/json" \ -d "<!DOCTYPE html><html><body><h1 style=\"color:blue;\">This is a heading</h1><p style=\"color:red;\">This is a paragraph.</body></html>"
In the image above, you may notice that we are embedding html in powerpoint (an existing PPT in Cloud storage).
In this article, we have learned the details for embedding HTML in PowerPoint using Java code snippets as well as how to insert Webpage into PowerPoint using cURL commands. You have observed that with few code lines, the whole conversion process is completed, and the resultant PPT is generated (while maintaining complete fidelity). In case you are interested in making modifications to the SDK codebase, you can download it from GitHub as it’s published under an MIT license. Nevertheless, if you encounter any issue while embedding HTML in PowerPoint or you have any further queries, please feel free to contact us via the free technical support forum.
We highly recommend visiting the following links to learn about: