この簡単なトピックでは、Java を使用して SVG を Presentation に変換する方法を説明します。このアプリケーションは、Windows、Linux、または macOS 内の Java 構成環境のいずれでも使用でき、**Java で SVG を PPTX にシームレスに変換し、サードパーティ ソフトウェアに依存することはありません。
Java で SVG を PPTX にエクスポートする手順
- リポジトリ マネージャーから Aspose.Slides for Java を追加するようにアプリケーションを構成します
- Presentation クラスのインスタンスをインスタンス化して、デフォルトのプレゼンテーションを作成します
- プレゼンテーション スライド コレクション内の最初のスライドを読み込みます
- SVG ファイルのコンテンツを開いて読み取り、それをプレゼンテーション画像コレクションに挿入します
- SVG 画像が追加されたスライド内に額縁形状を挿入する
- ディスクに SVG イメージを含むプレゼンテーションを保存します
Java で上記の手順に従うことで、SVG を PPT として保存 プレゼンテーションを簡単に実行できます。このプロセスは、Presentation クラス インスタンスを使用して新しいプレゼンテーションを作成し、スライド コレクション内の最初のスライドにアクセスすることによって開始されます。続いて、ソース SVG ファイルのコンテンツが読み取られ、プレゼンテーション画像コレクション内の IPPImage クラスのインスタンスに追加されます。追加された画像は、額縁形状内に挿入され、プレゼンテーションは PPTX 形式でディスクに保存されます。
Java で SVG を PPTX に変換するコード
import com.aspose.slides.IPPImage; | |
import com.aspose.slides.ISlide; | |
import com.aspose.slides.ISvgImage; | |
import com.aspose.slides.License; | |
import com.aspose.slides.Presentation; | |
import com.aspose.slides.SaveFormat; | |
import com.aspose.slides.ShapeType; | |
import com.aspose.slides.SvgImage; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
public class InsertSVG { | |
public static void main(String[] args) throws Exception{ | |
String filesPath = "/Documents/KnowledgeBase/TestData/"; | |
License svgImportlicense = new License(); | |
svgImportlicense.setLicense(filesPath + "Conholdate.Total.Product.Family.lic"); | |
//Generate a default presentation to insert an SVG image | |
Presentation SvgPresentation = new Presentation(); | |
//Access the first slide of the newly created presentation | |
ISlide slide = SvgPresentation.getSlides().get_Item(0); | |
//Load the SVG file content and add it to the presentation image collection | |
String svgContent = new String(Files.readAllBytes(Paths.get(filesPath + "410.svg"))); | |
ISvgImage svgImage = new SvgImage(svgContent); | |
IPPImage ppSVGImage = SvgPresentation.getImages().addImage(svgImage); | |
//Insert the SVG inside a picture frame shape | |
slide.getShapes().addPictureFrame(ShapeType.Rectangle, 0, 0, ppSVGImage.getWidth(), ppSVGImage.getHeight(), ppSVGImage); | |
//Save the presentation with the SVG image | |
SvgPresentation.save(filesPath + "PresWithSVG.pptx", SaveFormat.Pptx); | |
} | |
} |
Java SVG から PowerPoint への上記のコードを利用することで、シンプルな API インターフェイスを使用して簡単にプレゼンテーションを変換できます。新しいプレゼンテーションを作成したり、既存のプレゼンテーションをロードしたり、SVG 画像を任意のスライド内の任意の位置に挿入したり、画像のカスタム サイズを設定したりすることもできます。ソース SVG イメージは、Web やデータベースなどのソースからメモリ ストリームとしてロードすることもできます。
このトピックでは、Java を使用してプレゼンテーションに SVG を挿入する方法について説明します。 PowerPoint プレゼンテーション内に表を追加する方法に興味がある場合は、Javaを使用してスライドに表を挿入する方法 の記事を参照してください。