このチュートリアルには、Javaを使用してHTMLでPowerPointスライドを作成する方法に関する情報が含まれています。これは、新しいpresentationが作成されるか、既存のプレゼンテーションが読み込まれてHTMLとして保存される非常に単純なプロセスです。これにより、既存のプレゼンテーションをHTMLにレンダリングする場合に、数行のコードを使用してJavaのHTMLスライドをレンダリングできます。
Javaを使用してHTMLプレゼンテーションを作成する手順
- HTMLプレゼンテーションを作成するために、MavenリポジトリからプロジェクトにAspose.Slides for Javaを追加します
- 空のPresentationクラスオブジェクトを作成します
- Slideクラスオブジェクトを作成し、それにひし形を追加します
- ひし形のテキストを設定します
- 結果のプレゼンテーションをHTMLファイルとしてディスクに保存します
これらの手順は、新しいプレゼンテーションが作成され、任意のブラウザで開くことができるHTMLとして保存されるJavaを使用したHTMLプレゼンテーションの作成に役立ちます。既存のプレゼンテーションをロードしてHTMLプレゼンテーションを作成することもできるため、プレゼンテーションを最初から作成する必要はないことに注意してください。必要に応じて、選択したスライドを出力HTMLファイルに保存することもできます。
Javaを使用してHTMLプレゼンテーションスライドを作成するコード
import com.aspose.slides.License; | |
import com.aspose.slides.IAutoShape; | |
import com.aspose.slides.IParagraph; | |
import com.aspose.slides.IPortion; | |
import com.aspose.slides.ISlide; | |
import com.aspose.slides.ITextFrame; | |
import com.aspose.slides.Presentation; | |
import com.aspose.slides.SaveFormat; | |
import com.aspose.slides.ShapeType; | |
public class SlidesMainFunction { | |
public static void main(String[] args) {//Create PowerPoint Slides in HTML using Java | |
// Instantiate license to create presentation in HTML | |
License slidesLicense = new License(); | |
slidesLicense.setLicense("Aspose.Slides.lic"); | |
//Create an empty presentation class object | |
Presentation targetPresentation = new Presentation(); | |
try | |
{ | |
// Get access to the first slide instance from the default slides collection | |
ISlide targetSlide = targetPresentation.getSlides().get_Item(0); | |
// Add a diamond shape to display some text in it | |
IAutoShape targetShape = targetSlide.getShapes().addAutoShape(ShapeType.Diamond, 150, 75, 150, 50); | |
// Add a text frame in the diamond | |
targetShape.addTextFrame(" "); | |
// Get access to the newly created text frame | |
ITextFrame targetTxtFrame = targetShape.getTextFrame(); | |
// Get access to the first paragraph object in the text frame | |
IParagraph targetPara = targetTxtFrame.getParagraphs().get_Item(0); | |
// Get access to the first portion in the paragraph | |
IPortion targetPortion = targetPara.getPortions().get_Item(0); | |
// Add some test data to display in diamond shape | |
targetPortion.setText("Aspose sample text in the textbox"); | |
// Save the HTML presentation on the disk | |
targetPresentation.save("TextBox_out.html", SaveFormat.Html); | |
} | |
finally | |
{ | |
if (targetPresentation != null) | |
targetPresentation.dispose(); | |
} | |
System.out.println("Done"); | |
} | |
} |
このコードは、* Javaを使用したHTML表示の例*の1つを詳細に示しており、操作の完全なシーケンスが表示され、最後にHTML表示が行われます。新しいプレゼンテーションを作成するには、Presentation、ISlide、IAutoShape、ITextFrame、IParagraph、およびIPortionクラスのオブジェクトを順番に作成する必要があることがわかります。複数のスライドを作成して、MSPowerPointと同様のさまざまなタイプのコンテンツを追加することもできます。
この記事では、HTMLでPowerPointプレゼンテーションを作成する方法を学びました。ただし、プレゼンテーションを保護したい場合は、Javaを使用してPowerPointプレゼンテーションを保護する方法の記事を参照してください。