Aspose::Words::Saving::IPageSavingCallback Interface Referenceabstract

Detailed Description

Implement this interface if you want to control how Aspose.Words saves separate pages when saving a document to fixed page formats.

Examples

Shows how to use a callback to save a document to HTML page by page.

void PageFileNames()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Page 1.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page 2.");
builder->InsertImage(ImageDir + u"Logo.jpg");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page 3.");
// Create an "HtmlFixedSaveOptions" object, which we can pass to the document's "Save" method
// to modify how we convert the document to HTML.
auto htmlFixedSaveOptions = MakeObject<HtmlFixedSaveOptions>();
// We will save each page in this document to a separate HTML file in the local file system.
// Set a callback that allows us to name each output HTML document.
htmlFixedSaveOptions->set_PageSavingCallback(MakeObject<ExSavingCallback::CustomFileNamePageSavingCallback>());
doc->Save(ArtifactsDir + u"SavingCallback.PageFileNames.html", htmlFixedSaveOptions);
ArrayPtr<String> filePaths = System::IO::Directory::GetFiles(ArtifactsDir)
->LINQ_Where([](String s) { return s.StartsWith(ArtifactsDir + u"SavingCallback.PageFileNames.Page_"); })
->LINQ_ToArray();
ASSERT_EQ(3, filePaths->get_Length());
}
class CustomFileNamePageSavingCallback : public IPageSavingCallback
{
public:
void PageSaving(SharedPtr<PageSavingArgs> args) override
{
String outFileName = String::Format(u"{0}SavingCallback.PageFileNames.Page_{1}.html", ArtifactsDir, args->get_PageIndex());
// Below are two ways of specifying where Aspose.Words will save each page of the document.
// 1 - Set a filename for the output page file:
args->set_PageFileName(outFileName);
// 2 - Create a custom stream for the output page file:
args->set_PageStream(MakeObject<System::IO::FileStream>(outFileName, System::IO::FileMode::Create));
ASSERT_FALSE(args->get_KeepPageStreamOpen());
}
};

#include <Aspose.Words.Cpp/Saving/IPageSavingCallback.h>

+ Inheritance diagram for Aspose::Words::Saving::IPageSavingCallback:

Public Member Functions

virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
virtual void PageSaving (SharedPtr< PageSavingArgs > args)=0
 Called when Aspose.Words saves a separate page to fixed page formats. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::Saving::IPageSavingCallback::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ Is()

virtual bool Aspose::Words::Saving::IPageSavingCallback::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from System::Object.

◆ PageSaving()

virtual void Aspose::Words::Saving::IPageSavingCallback::PageSaving ( System::SharedPtr< Aspose::Words::Saving::PageSavingArgs args)
pure virtual

Called when Aspose.Words saves a separate page to fixed page formats.

Examples

Shows how to use a callback to save a document to HTML page by page.

void PageFileNames()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Page 1.");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page 2.");
builder->InsertImage(ImageDir + u"Logo.jpg");
builder->InsertBreak(BreakType::PageBreak);
builder->Writeln(u"Page 3.");
// Create an "HtmlFixedSaveOptions" object, which we can pass to the document's "Save" method
// to modify how we convert the document to HTML.
auto htmlFixedSaveOptions = MakeObject<HtmlFixedSaveOptions>();
// We will save each page in this document to a separate HTML file in the local file system.
// Set a callback that allows us to name each output HTML document.
htmlFixedSaveOptions->set_PageSavingCallback(MakeObject<ExSavingCallback::CustomFileNamePageSavingCallback>());
doc->Save(ArtifactsDir + u"SavingCallback.PageFileNames.html", htmlFixedSaveOptions);
ArrayPtr<String> filePaths = System::IO::Directory::GetFiles(ArtifactsDir)
->LINQ_Where([](String s) { return s.StartsWith(ArtifactsDir + u"SavingCallback.PageFileNames.Page_"); })
->LINQ_ToArray();
ASSERT_EQ(3, filePaths->get_Length());
}
class CustomFileNamePageSavingCallback : public IPageSavingCallback
{
public:
void PageSaving(SharedPtr<PageSavingArgs> args) override
{
String outFileName = String::Format(u"{0}SavingCallback.PageFileNames.Page_{1}.html", ArtifactsDir, args->get_PageIndex());
// Below are two ways of specifying where Aspose.Words will save each page of the document.
// 1 - Set a filename for the output page file:
args->set_PageFileName(outFileName);
// 2 - Create a custom stream for the output page file:
args->set_PageStream(MakeObject<System::IO::FileStream>(outFileName, System::IO::FileMode::Create));
ASSERT_FALSE(args->get_KeepPageStreamOpen());
}
};

◆ Type()

static const System::TypeInfo& Aspose::Words::Saving::IPageSavingCallback::Type ( )
static