この簡単なトピックでは、C# を使用して、PowerPoint に依存せずに SVG を Presentation に変換する方法を示します。 C# で SVG を PPTX に変換するために、サードパーティ ソフトウェアや相互運用ライブラリは必要ありません。このアプリケーションは、Windows、Linux、または macOS 内の任意の .NET 構成環境で使用でき、サンプル コードはすべての .NET プラットフォームでシームレスに実行できます。
C# で SVG を PPTX にエクスポートする手順
- NuGet.org から Aspose.Slides for .NET パッケージを追加するようにアプリケーションを構成します
- Presentation クラスのインスタンスを作成して、デフォルトのプレゼンテーションを作成します
- プレゼンテーション スライド コレクション内の最初の既定のスライドにアクセスする
- SVG ファイルのコンテンツを文字列として読み取り、それをプレゼンテーション画像コレクションに挿入します
- SVG 画像が追加された選択したスライド内に額縁形状を追加します
- プレゼンテーションを SVG イメージと共にディスクに保存します
前述の C# の手順を使用して、SVG を PPT として保存 プレゼンテーションを簡単に行うことができます。このプロセスは、Presentation クラスのインスタンスを作成し、slides コレクションのデフォルトの最初のスライドにアクセスすることから始まります。次に、SVG ファイルのコンテンツがディスクから文字列として読み取られ、プレゼンテーション画像コレクション内の IPPImage に追加されます。最後に、追加した SVG を使用してスライド内に額縁形状を追加し、プレゼンテーションをディスクに保存します。
C# で SVG を PPTX に変換するコード
using Aspose.Slides; | |
namespace TestSlides | |
{ | |
public class InsertSVG | |
{ | |
public static void AddSvgToSlide() | |
{ | |
string filesPath = @"/Documents/KnowledgeBase/TestData/"; | |
License license = new License(); | |
license.SetLicense(filesPath + "Conholdate.Total.Product.Family.lic"); | |
//Create a new presentation to insert an SVG image | |
Presentation SvgPresentation = new Presentation(); | |
//Access the first default slide of the presentation | |
ISlide slide = SvgPresentation.Slides[0]; | |
//Load the SVG file content and add that to the presentation image collection | |
var svgContent = System.IO.File.ReadAllText(filesPath + "410.svg"); | |
ISvgImage svgImage = new SvgImage(svgContent); | |
IPPImage ppSVGImage = SvgPresentation.Images.AddImage(svgImage); | |
//Insert the SVG inside a picture frame shape | |
slide.Shapes.AddPictureFrame(ShapeType.Rectangle, 0, 0, ppSVGImage.Width, ppSVGImage.Height, ppSVGImage); | |
//Save the presentation with an SVG image | |
SvgPresentation.Save(filesPath + "PresWithSVG.pptx", Aspose.Slides.Export.SaveFormat.Pptx); | |
} | |
} | |
} |
このチュートリアルでは、C# を使用してプレゼンテーションに SVG を挿入する方法について説明します。 PowerPoint プレゼンテーション内に表を追加する方法については、C# を使用して PowerPoint で表を作成する方法 の記事を参照してください。