Aspose::Words::Layout::IPageLayoutCallback interface
Contents
[
Hide
]IPageLayoutCallback interface
Implement this interface if you want to have your own custom method called during build and rendering of page layout model.
class IPageLayoutCallback : public virtual System::Object
Methods
Method | Description |
---|---|
GetType() const override | |
Is(const System::TypeInfo&) const override | |
virtual Notify(System::SharedPtr<Aspose::Words::Layout::PageLayoutCallbackArgs>) | This is called to notify of layout build and rendering progress. |
static Type() |
Remarks
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.
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())
{
case PageLayoutEvent::PartReflowFinished:
NotifyPartFinished(a);
break;
case PageLayoutEvent::ConversionFinished:
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);
}
}
};
See Also
- Namespace Aspose::Words::Layout
- Library Aspose.Words for C++