このチュートリアルでは、PowerPoint に依存せずに Python を使用して SVG を Presentation に変換する方法に焦点を当てます。このアプリケーションは、Python で SVG を PPTX に変換するために、Windows、Linux、または macOS などのオペレーティング システムの .NET コアおよび Python で構成された環境内で利用できます。
Python で SVG を PPTX にエクスポートする手順
- アプリケーションで環境を .NET 経由で Aspose.Slides for Python を使用 に構成して、SVG をプレゼンテーションに変換します
- Presentation クラスのインスタンスを使用してデフォルトのプレゼンテーションを作成します
- プレゼンテーションのスライド コレクションから最初のスライドを読み込みます
- SVG ファイルを開き、その内容を文字列として読み取り、それをプレゼンテーション画像コレクションに挿入します
- IPictureFrame のインスタンスを使用して、SVG 画像が追加されたスライド内に画像フレームを挿入します。
- SVG イメージを含む PPTX ファイルをディスクに保存します。
Python の上記の簡単な手順では、単純な API インターフェイスを使用して SVG を PPT プレゼンテーションとしてエクスポートします。まず、Presentation クラスのインスタンスを使用して既定のプレゼンテーションを作成し、プレゼンテーションのスライド コレクションから最初の既定のスライドにアクセスします。次に、SVG ファイルのコンテンツをディスクから文字列として読み込んで読み込み、それをプレゼンテーション画像コレクション内の IPPImage に追加します。最後に、IPictureFrame クラス インスタンスを使用して、結果のプレゼンテーションをディスクに保存する前に、追加された SVG ファイルを利用するピクチャ フレーム形状が追加されます。
Python で SVG を PPTX に変換するコード
import aspose.slides as slides | |
filepath = "C://Words//" | |
#Applying the licence for Aspose.Slides to convert SVG to PPTX | |
svgtoSlidesLicense = slides.License() | |
svgtoSlidesLicense.set_license(filepath + "Conholdate.Total.Product.Family.lic") | |
# Make an empty presentation using the Presentation class object | |
with slides.Presentation() as sampleSvgPres: | |
#Access the first slide of the newly created presentation | |
slideForSvg = sampleSvgPres.slides[0] | |
#Load the SVG file content and insert that inside the presentation image collection | |
with open(filepath + "410.svg", 'r') as svgfile: | |
svgContent = svgfile.read().rstrip() | |
ppSVGImage = slides.SvgImage(svgContent) | |
#Add an SVG Image from the disk inside the images collection of the presentation | |
svgImageForSlide = sampleSvgPres.images.add_image(ppSVGImage) | |
#Insert a picture frame inside the shapes collection of the slide | |
slideForSvg.shapes.add_picture_frame(slides.ShapeType.RECTANGLE, 0, 0, 720, 540, svgImageForSlide) | |
#Save the presentation in PPTX format with an SVG image on the disk | |
slideForSvg.save(filepath + "PresentationWithSvg.pptx", slides.export.SaveFormat.PPTX) | |
print("Process Completed") | |
このトピックでは、Python を使用してプレゼンテーションに SVG を挿入する方法について説明しました。 PowerPoint スライド内に表を挿入する方法に興味がある場合は、Python を使用して PowerPoint で表を作成する方法 の記事を参照してください。