プレゼンテーションの保存 - C++ PowerPointライブラリ

この記事では、プレゼンテーションを保存する方法について説明します。

Presentationクラスは、プレゼンテーションの内容を保持します。ゼロからプレゼンテーションを作成するか、既存のものを修正した場合、完了したらプレゼンテーションを保存したいと思います。Aspose.Slides for C++を使用すると、プレゼンテーションをファイルまたはストリームとして保存できます。この記事では、さまざまな方法でプレゼンテーションを保存する方法を説明します。

ファイルへのプレゼンテーションの保存

PresentationクラスのSaveメソッドを呼び出すことで、プレゼンテーションをファイルに保存します。ファイル名と保存形式をSaveメソッドに渡すだけです。以下の例は、Aspose.Slides for C++を使用してプレゼンテーションを保存する方法を示しています。

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
const String outPath = u"../out/SaveToFile_out.ppt";
SharedPtr<Presentation> pres = MakeObject<Presentation>();
//pres->get_ProtectionManager()->Encrypt(u"pass");
//...do some work here..
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

ストリームへのプレゼンテーションの保存

出力ストリームをPresentationクラスのSaveメソッドに渡すことで、プレゼンテーションをストリームに保存することが可能です。プレゼンテーションを保存できるストリームの種類は多くあります。以下の例では、新しいプレゼンテーションファイルを作成し、形状にテキストを追加し、プレゼンテーションをストリームに保存します。

const String outPath = u"../out/Save_As_Stream_out.pptx";
SharedPtr<Presentation> pres = MakeObject<Presentation>();
SharedPtr<IAutoShape> shape = pres->get_Slides()->idx_get(0)->get_Shapes()->AddAutoShape(Aspose::Slides::ShapeType::Rectangle, 200, 200, 200, 200);
/// Load the video file to stream
System::SharedPtr<System::IO::Stream> stream = System::MakeObject<System::IO::FileStream>(outPath, System::IO::FileMode::Create);
pres->Save(stream, Aspose::Slides::Export::SaveFormat::Pptx);

事前定義されたビュータイプを使用したプレゼンテーションの保存

Aspose.Slides for C++は、PowerPointで開くときに生成されたプレゼンテーションのビュータイプを設定するための機能を提供します。この機能は、ViewPropertiesクラスを通じて使用します。LastViewプロパティは、ViewType列挙体を使用してビュータイプを設定するために使用されます。

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
const String outPath = u"../out/SaveAsPredefinedViewType_out.ppt";
SharedPtr<Presentation> pres = MakeObject<Presentation>();
pres->get_ViewProperties()->set_LastView(Aspose::Slides::ViewType::SlideMasterView);
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

厳密なOffice Open XML形式でのプレゼンテーションの保存

Aspose.Slidesは、プレゼンテーションを厳密なOffice Open XML形式で保存することを許可します。この目的のために、プレゼンテーションファイルを保存する際にConformanceプロパティを設定することができるPptxOptionsクラスを提供します。値をConformance.Iso29500_2008_Strictに設定すると、出力プレゼンテーションファイルは厳密なOffice Open XML形式で保存されます。

以下のサンプルコードは、プレゼンテーションを作成し、厳密なOffice Open XML形式で保存します。プレゼンテーションのSaveメソッドを呼び出す際、PptxOptionsオブジェクトがConformanceプロパティをConformance.Iso29500_2008_Strictに設定して渡されます。

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
const String outPath = u"../out/SaveToStrictOpenXML_out.pptx";
//Instantiate Presentation object
SharedPtr<Presentation> pres = MakeObject<Presentation>();
//Access first slide
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// Add an AutoShape of Rectangle type
SharedPtr<IAutoShape> ashp = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 150, 75, 150, 50);
//Setting options for strick XML
SharedPtr<PptxOptions> options = MakeObject<PptxOptions>();
options->set_Conformance(Conformance::Iso29500_2008_Strict);
//Save presentation
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx, options);

パーセンテージでの進捗更新の保存

新しいIProgressCallbackインターフェースがISaveOptionsインターフェースおよびSaveOptions抽象クラスに追加されました。IProgressCallbackインターフェースは、パーセンテージでの保存進捗更新のためのコールバックオブジェクトを表します。

以下のコードスニペットは、IProgressCallbackインターフェースの使用方法を示しています。

const String templatePath = u"../templates/SamplePresentation.pptx";
const String outPath = u"../out/SamplePresentation_out.pptx";
auto presentation = System::MakeObject<Presentation>(templatePath);
System::SharedPtr<ISaveOptions> saveOptions = System::MakeObject<PdfOptions>();
System::SharedPtr<IProgressCallback> callBack = System::MakeObject<ExportProgressHandler>();
saveOptions->set_ProgressCallback(callBack);
presentation->Save(outPath, Aspose::Slides::Export::SaveFormat::Pdf, saveOptions);
class ExportProgressHandler : public IProgressCallback
{
public:
void Reporting(double progressValue)
{
System::Console::WriteLine(u"% completed", progressValue);
}
};