CssSavingArgs Class |
Namespace: Aspose.Words.Saving
The CssSavingArgs type exposes the following members.
Name | Description | |
---|---|---|
![]() ![]() | CssStream |
Allows to specify the stream where the CSS information will be saved to.
|
![]() ![]() | Document |
Gets the document object that is currently being saved.
|
![]() ![]() | IsExportNeeded |
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.
|
![]() ![]() | KeepCssStreamOpen |
Specifies whether Aspose.Words should keep the stream open or close it after saving an CSS information.
|
Name | Description | |
---|---|---|
![]() | Equals | (Inherited from Object.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetType | (Inherited from Object.) |
![]() | ToString | (Inherited from Object.) |
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.
public void CssSavingCallback() { // Open a document to be converted to html Document doc = new Document(MyDir + "Rendering.docx"); // If our output document will produce a CSS stylesheet, we can use an HtmlSaveOptions to control where it is saved HtmlSaveOptions options = new HtmlSaveOptions(); // By default, a CSS stylesheet is stored inside its HTML document, but we can have it saved to a separate file options.CssStyleSheetType = CssStyleSheetType.External; // We can designate a filename for our stylesheet like this options.CssStyleSheetFileName = ArtifactsDir + "SavingCallback.CssSavingCallback.css"; // A custom ICssSavingCallback implementation can also control where that stylesheet will be saved and linked to by the Html document // This callback will override the filename we specified above in options.CssStyleSheetFileName, // but will give us more control over the saving process options.CssSavingCallback = new CustomCssSavingCallback(ArtifactsDir + "SavingCallback.CssSavingCallback.css", true, false); // The CssSaving() method of our callback will be called at this stage doc.Save(ArtifactsDir + "SavingCallback.CssSavingCallback.html", options); } /// <summary> /// Designates a filename and other parameters for the saving of a CSS stylesheet /// </summary> private class CustomCssSavingCallback : ICssSavingCallback { public CustomCssSavingCallback(string cssDocFilename, bool isExportNeeded, bool keepCssStreamOpen) { mCssTextFileName = cssDocFilename; mIsExportNeeded = isExportNeeded; mKeepCssStreamOpen = keepCssStreamOpen; } public void CssSaving(CssSavingArgs args) { // Set up the stream that will create the CSS document args.CssStream = new FileStream(mCssTextFileName, FileMode.Create); Assert.True(args.CssStream.CanWrite); args.IsExportNeeded = mIsExportNeeded; args.KeepCssStreamOpen = mKeepCssStreamOpen; // We can also access the original document here like this Assert.True(args.Document.OriginalFileName.EndsWith("Rendering.docx")); } private readonly string mCssTextFileName; private readonly bool mIsExportNeeded; private readonly bool mKeepCssStreamOpen; }