Aspose::Words::Saving::ICssSavingCallback Interface Referenceabstract

Detailed Description

Implement this interface if you want to control how Aspose.Words saves CSS (Cascading Style Sheet) when saving a document to HTML.

Examples

Shows how to work with CSS stylesheets that an HTML conversion creates.

void ExternalCssFilenames()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Create an "HtmlFixedSaveOptions" object, which we can pass to the document's "Save" method
// to modify how we convert the document to HTML.
auto options = MakeObject<HtmlSaveOptions>();
// Set the "CssStylesheetType" property to "CssStyleSheetType.External" to
// accompany a saved HTML document with an external CSS stylesheet file.
options->set_CssStyleSheetType(CssStyleSheetType::External);
// Below are two ways of specifying directories and filenames for output CSS stylesheets.
// 1 - Use the "CssStyleSheetFileName" property to assign a filename to our stylesheet:
options->set_CssStyleSheetFileName(ArtifactsDir + u"SavingCallback.ExternalCssFilenames.css");
// 2 - Use a custom callback to name our stylesheet:
options->set_CssSavingCallback(
MakeObject<ExSavingCallback::CustomCssSavingCallback>(ArtifactsDir + u"SavingCallback.ExternalCssFilenames.css", true, false));
doc->Save(ArtifactsDir + u"SavingCallback.ExternalCssFilenames.html", options);
}
class CustomCssSavingCallback : public ICssSavingCallback
{
public:
CustomCssSavingCallback(String cssDocFilename, bool isExportNeeded, bool keepCssStreamOpen) : mIsExportNeeded(false), mKeepCssStreamOpen(false)
{
mCssTextFileName = cssDocFilename;
mIsExportNeeded = isExportNeeded;
mKeepCssStreamOpen = keepCssStreamOpen;
}
void CssSaving(SharedPtr<CssSavingArgs> args) override
{
// We can access the entire source document via the "Document" property.
ASSERT_TRUE(args->get_Document()->get_OriginalFileName().EndsWith(u"Rendering.docx"));
args->set_CssStream(MakeObject<System::IO::FileStream>(mCssTextFileName, System::IO::FileMode::Create));
args->set_IsExportNeeded(mIsExportNeeded);
args->set_KeepCssStreamOpen(mKeepCssStreamOpen);
ASSERT_TRUE(args->get_CssStream()->get_CanWrite());
}
private:
String mCssTextFileName;
bool mIsExportNeeded;
bool mKeepCssStreamOpen;
};

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

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

Public Member Functions

virtual void CssSaving (SharedPtr< CssSavingArgs > args)=0
 Called when Aspose.Words saves an CSS (Cascading Style Sheet). More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ CssSaving()

virtual void Aspose::Words::Saving::ICssSavingCallback::CssSaving ( System::SharedPtr< Aspose::Words::Saving::CssSavingArgs args)
pure virtual

Called when Aspose.Words saves an CSS (Cascading Style Sheet).

Examples

Shows how to work with CSS stylesheets that an HTML conversion creates.

void ExternalCssFilenames()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Create an "HtmlFixedSaveOptions" object, which we can pass to the document's "Save" method
// to modify how we convert the document to HTML.
auto options = MakeObject<HtmlSaveOptions>();
// Set the "CssStylesheetType" property to "CssStyleSheetType.External" to
// accompany a saved HTML document with an external CSS stylesheet file.
options->set_CssStyleSheetType(CssStyleSheetType::External);
// Below are two ways of specifying directories and filenames for output CSS stylesheets.
// 1 - Use the "CssStyleSheetFileName" property to assign a filename to our stylesheet:
options->set_CssStyleSheetFileName(ArtifactsDir + u"SavingCallback.ExternalCssFilenames.css");
// 2 - Use a custom callback to name our stylesheet:
options->set_CssSavingCallback(
MakeObject<ExSavingCallback::CustomCssSavingCallback>(ArtifactsDir + u"SavingCallback.ExternalCssFilenames.css", true, false));
doc->Save(ArtifactsDir + u"SavingCallback.ExternalCssFilenames.html", options);
}
class CustomCssSavingCallback : public ICssSavingCallback
{
public:
CustomCssSavingCallback(String cssDocFilename, bool isExportNeeded, bool keepCssStreamOpen) : mIsExportNeeded(false), mKeepCssStreamOpen(false)
{
mCssTextFileName = cssDocFilename;
mIsExportNeeded = isExportNeeded;
mKeepCssStreamOpen = keepCssStreamOpen;
}
void CssSaving(SharedPtr<CssSavingArgs> args) override
{
// We can access the entire source document via the "Document" property.
ASSERT_TRUE(args->get_Document()->get_OriginalFileName().EndsWith(u"Rendering.docx"));
args->set_CssStream(MakeObject<System::IO::FileStream>(mCssTextFileName, System::IO::FileMode::Create));
args->set_IsExportNeeded(mIsExportNeeded);
args->set_KeepCssStreamOpen(mKeepCssStreamOpen);
ASSERT_TRUE(args->get_CssStream()->get_CanWrite());
}
private:
String mCssTextFileName;
bool mIsExportNeeded;
bool mKeepCssStreamOpen;
};

◆ GetType()

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

Reimplemented from System::Object.

◆ Is()

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

Reimplemented from System::Object.

◆ Type()

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