PowerPoint ドキュメントと比較して、画像ファイルは、特定のソフトウェアを必要とせずに、ほぼすべてのデバイスで開くことができるため、表示しやすくなっています。PowerPoint ドキュメントをさまざまなデバイスで利用できるようにしたい場合、画像に変換することができます。今回は、Spire.Presentation for Java を使用して、Java で PowerPoint ドキュメントをさまざまな画像形式に変換する方法を説明します。 PowerPoint ドキュメントを JPG または PNG 画像に変換する PowerPoint ドキュメントを TIFF 画像に変換する PowerPoint ドキュメントを SVG 画像に変換する Spire.Presentation for Java をインストールします まず、Spire.Presentation for Java を Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。 <repositories> <repository> <id>com.e-iceblue</id> <name>e-iceblue</name> <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.presentation</artifactId> <version>7.10.1</version> </dependency> </dependencies> PowerPoint ドキュメントを JPG または PNG 画像に変換する PowerPointドキュメントを JPG または PNG 画像に変換する手順は次のとおりです。 Presentation クラスのインスタンスを作成します。 Presentation.loadFromFile() メソッドを使用して PowerPoint ドキュメントを読み込みます。 PowerPoint ドキュメント内のすべてのスライドを循環させます。 ISlide.saveAsImage() メソッドを使用して、各スライドを BufferedImage クラスのオブジェクトとして保存します。 ImageIO.write() メソッドを使用して、BufferedImage クラスのオブジェクトを PNG ファイルまたは JPG ファイルに保存します。 Java import com.spire.presentation.ISlide; import com.spire.presentation.Presentation; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; public class convertPowerPointToPngOrJpg { public static void main(String []args) throws Exception { //Presentationクラスのインスタンスを作成する Presentation presentation = new Presentation(); //PowerPointドキュメントを読み込む presentation.loadFromFile("C:/Sample.pptx"); //PowerPointドキュメント内の全スライドを循環させる for(int i = 0; i < presentation.getSlides().getCount(); i++) { ISlide slide = presentation.getSlides().get(i); //各スライドをPNG画像で保存する BufferedImage image = slide.saveAsImage(); String fileName = String.format("画像-%1$s.png", i); ImageIO.write(image, "PNG",new File(fileName)); } } } PowerPoint ドキュメントを TIFF 画像に変換する PowerPoint ドキュメントを TIFF 画像に変換する手順は次のとおりです。 Presentation クラスのインスタンスを作成します。 Presentation.loadFromFile() メソッドを使用して PowerPoint ドキュメントを読み込みます。 Presentation.saveToFile(String, FileFormat) メソッドを使用して、PowerPoint ドキュメントを TIFF 画像に変換します。 Java import com.spire.presentation.FileFormat; import com.spire.presentation.Presentation; public class convertPowerPointToTiff { public static void main(String []args) throws Exception { //Presentationクラスのインスタンスを作成する Presentation presentation = new Presentation(); //PowerPointドキュメントを読み込む presentation.loadFromFile("C:/Sample.pptx"); //PowerPointドキュメントをTIFF画像に変換する presentation.saveToFile("TIFF.tiff", FileFormat.TIFF); } } PowerPointド キュメントを SVG 画像に変換する PowerPoint ドキュメントを SVG 画像に変換する手順を説明します。 Presentation クラスのインスタンスを作成します。 Presentation.loadFromFile() メソッドを使用して PowerPoint ドキュメントを読み込みます。 Presentation.saveToSVG() メソッドを使用して、PowerPoint ドキュメントを SVG に変換し、その結果をバイト配列の ArrayList に保存します。 ArrayList 内のバイト配列をループ処理します。 ArrayList.get(int) メソッドを使用して、現在のバイト配列を取得します。 FileOutputStream クラスのインスタンスを作成し、FileOutputStream.write() メソッドを使用してバイト配列を SVG ファイルに保存します。 Java import com.spire.presentation.Presentation; import java.io.FileOutputStream; import java.util.ArrayList; public class convertPowerPointToSVG { public static void main(String []args) throws Exception { //Presentationクラスのインスタンスを作成する Presentation presentation = new Presentation(); //PowerPointドキュメントを読み込む presentation.loadFromFile("C:/Sample.pptx"); //PowerPointドキュメントをSVGに変換し、その結果をバイト配列のArrayListに保存する ArrayList svgBytes =(ArrayList) presentation.saveToSVG(); int len = svgBytes.size(); //ArrayListのバイト配列をループする for (int i = 0; i < len; i++) { //現在のバイト配列を取得する byte[] bytes = (byte[]) svgBytes.get(i); //出力ファイル名を指定する String fileName= String.format("ToSVG-%d.svg", i); //FileOutputStreamクラスのインスタンスを作成する FileOutputStream stream = new FileOutputStream(fileName); //バイト配列をSVGファイルに保存する stream.write(bytes); } } } 一時ライセンスを申請する 結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。 にお問い合わせ、30 日間有効な一時ライセンスを取得してください。