search/mag_sel search/close
Aspose::Words::Saving::CssSavingArgs Class Reference

Provides data for the CssSaving() event.

By default, when Aspose.Words saves a document to HTML, it saves CSS information inline (as a value of the style attribute on every element).

CssSavingArgs allows to save CSS information into file by providing your own stream object.

To save CSS into stream, use the CssStream property.

To suppress saving CSS into a file and embedding to HTML document use the IsExportNeeded property.

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/CssSavingArgs.h>

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

Public Member Functions

SharedPtr< Streamget_CssStream () const
 Allows to specify the stream where the CSS information will be saved to. More...
 
SharedPtr< Documentget_Document () const
 Gets the document object that is currently being saved. More...
 
bool get_IsExportNeeded () const
 Allows to specify whether the CSS will be exported to file and embedded to HTML document. Default is true. When this property is false, the CSS information will not be saved to a CSS file and will not be embedded to HTML document. More...
 
bool get_KeepCssStreamOpen () const
 Specifies whether Aspose.Words should keep the stream open or close it after saving an CSS information. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_CssStream (SharedPtr< Stream > value)
 Setter for get_CssStream. More...
 
void set_IsExportNeeded (bool value)
 Setter for get_IsExportNeeded. More...
 
void set_KeepCssStreamOpen (bool value)
 Setter for get_KeepCssStreamOpen. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ get_CssStream()

System::SharedPtr<System::IO::Stream> Aspose::Words::Saving::CssSavingArgs::get_CssStream ( ) const

Allows to specify the stream where the CSS information will be saved to.

This property allows you to save CSS information to a stream.

The default value is null. This property doesn't suppress saving CSS information to a file or embedding to HTML document. To suppress exporting CSS use the IsExportNeeded property.

Using ICssSavingCallback you cannot substitute CSS with another. It is intended only for saving CSS to a stream.

See also
Aspose::Words::Saving::CssSavingArgs::get_KeepCssStreamOpen
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;
};

◆ get_Document()

System::SharedPtr<Aspose::Words::Document> Aspose::Words::Saving::CssSavingArgs::get_Document ( ) const

Gets the document object that is currently being saved.

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;
};

◆ get_IsExportNeeded()

bool Aspose::Words::Saving::CssSavingArgs::get_IsExportNeeded ( ) const

Allows to specify whether the CSS will be exported to file and embedded to HTML document. Default is true. When this property is false, the CSS information will not be saved to a CSS file and will not be embedded to HTML document.

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;
};

◆ get_KeepCssStreamOpen()

bool Aspose::Words::Saving::CssSavingArgs::get_KeepCssStreamOpen ( ) const

Specifies whether Aspose.Words should keep the stream open or close it after saving an CSS information.

Default is false and Aspose.Words will close the stream you provided in the CssStream property after writing an CSS information into it. Specify true to keep the stream open.

See also
Aspose::Words::Saving::CssSavingArgs::get_CssStream
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::CssSavingArgs::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ Is()

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

Reimplemented from System::Object.

◆ set_CssStream()

void Aspose::Words::Saving::CssSavingArgs::set_CssStream ( System::SharedPtr< System::IO::Stream value)

◆ set_IsExportNeeded()

void Aspose::Words::Saving::CssSavingArgs::set_IsExportNeeded ( bool  value)

◆ set_KeepCssStreamOpen()

void Aspose::Words::Saving::CssSavingArgs::set_KeepCssStreamOpen ( bool  value)

◆ Type()

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