Aspose::Words::Layout::IPageLayoutCallback Interface Referenceabstract

Detailed Description

Implement this interface if you want to have your own custom method called during build and rendering of page layout model.

The primary use for this interface is to allow application code to abort build process.

It is possible to build page layout model for only a few pages at start of the document then abort process and render only what has been built already.

Note, however, that rendering results may not match what would be rendered for each page if process would have finished.

This technique may not work for every document or may fail completely.

See also
Aspose::Words::Layout::LayoutOptions::get_Callback
Examples

Shows how to track layout changes with a layout callback.

void PageLayoutCallback()
{
auto doc = MakeObject<Document>();
doc->get_BuiltInDocumentProperties()->set_Title(u"My Document");
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
doc->get_LayoutOptions()->set_Callback(MakeObject<ExLayout::RenderPageLayoutCallback>());
doc->UpdatePageLayout();
doc->Save(ArtifactsDir + u"Layout.PageLayoutCallback.pdf");
}
class RenderPageLayoutCallback : public IPageLayoutCallback
{
public:
void Notify(SharedPtr<PageLayoutCallbackArgs> a) override
{
switch (a->get_Event())
{
NotifyPartFinished(a);
break;
NotifyConversionFinished(a);
break;
default:
break;
}
}
RenderPageLayoutCallback() : mNum(0)
{
}
private:
int mNum;
void NotifyPartFinished(SharedPtr<PageLayoutCallbackArgs> a)
{
std::cout << "Part at page " << (a->get_PageIndex() + 1) << " reflow." << std::endl;
RenderPage(a, a->get_PageIndex());
}
void NotifyConversionFinished(SharedPtr<PageLayoutCallbackArgs> a)
{
std::cout << "Document \"" << a->get_Document()->get_BuiltInDocumentProperties()->get_Title() << "\" converted to page format." << std::endl;
}
void RenderPage(SharedPtr<PageLayoutCallbackArgs> a, int pageIndex)
{
auto saveOptions = MakeObject<ImageSaveOptions>(SaveFormat::Png);
saveOptions->set_PageSet(MakeObject<PageSet>(pageIndex));
{
auto stream = MakeObject<System::IO::FileStream>(ArtifactsDir + String::Format(u"PageLayoutCallback.page-{0} {1}.png", pageIndex + 1, ++mNum),
System::IO::FileMode::Create);
a->get_Document()->Save(stream, saveOptions);
}
}
};

#include <Aspose.Words.Cpp/Layout/IPageLayoutCallback.h>

+ Inheritance diagram for Aspose::Words::Layout::IPageLayoutCallback:

Public Member Functions

virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
virtual void Notify (SharedPtr< PageLayoutCallbackArgs > args)=0
 This is called to notify of layout build and rendering progress. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::Layout::IPageLayoutCallback::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ Is()

virtual bool Aspose::Words::Layout::IPageLayoutCallback::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from System::Object.

◆ Notify()

virtual void Aspose::Words::Layout::IPageLayoutCallback::Notify ( System::SharedPtr< Aspose::Words::Layout::PageLayoutCallbackArgs args)
pure virtual

This is called to notify of layout build and rendering progress.

Exception when thrown by implementation aborts layout build process.

Parameters
argsAn argument of the event.
Examples

Shows how to track layout changes with a layout callback.

void PageLayoutCallback()
{
auto doc = MakeObject<Document>();
doc->get_BuiltInDocumentProperties()->set_Title(u"My Document");
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
doc->get_LayoutOptions()->set_Callback(MakeObject<ExLayout::RenderPageLayoutCallback>());
doc->UpdatePageLayout();
doc->Save(ArtifactsDir + u"Layout.PageLayoutCallback.pdf");
}
class RenderPageLayoutCallback : public IPageLayoutCallback
{
public:
void Notify(SharedPtr<PageLayoutCallbackArgs> a) override
{
switch (a->get_Event())
{
NotifyPartFinished(a);
break;
NotifyConversionFinished(a);
break;
default:
break;
}
}
RenderPageLayoutCallback() : mNum(0)
{
}
private:
int mNum;
void NotifyPartFinished(SharedPtr<PageLayoutCallbackArgs> a)
{
std::cout << "Part at page " << (a->get_PageIndex() + 1) << " reflow." << std::endl;
RenderPage(a, a->get_PageIndex());
}
void NotifyConversionFinished(SharedPtr<PageLayoutCallbackArgs> a)
{
std::cout << "Document \"" << a->get_Document()->get_BuiltInDocumentProperties()->get_Title() << "\" converted to page format." << std::endl;
}
void RenderPage(SharedPtr<PageLayoutCallbackArgs> a, int pageIndex)
{
auto saveOptions = MakeObject<ImageSaveOptions>(SaveFormat::Png);
saveOptions->set_PageSet(MakeObject<PageSet>(pageIndex));
{
auto stream = MakeObject<System::IO::FileStream>(ArtifactsDir + String::Format(u"PageLayoutCallback.page-{0} {1}.png", pageIndex + 1, ++mNum),
System::IO::FileMode::Create);
a->get_Document()->Save(stream, saveOptions);
}
}
};

◆ Type()

static const System::TypeInfo& Aspose::Words::Layout::IPageLayoutCallback::Type ( )
static