Click or drag to resize

CssStyleSheetType Enumeration

Specifies how CSS (Cascading Style Sheet) styles are exported to HTML.

Namespace:  Aspose.Words.Saving
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public enum CssStyleSheetType
Members
  Member nameValueDescription
Inline0 CSS styles are written inline (as a value of the style attribute on every element).
Embedded1 CSS styles are written separately from the content in a style sheet embedded in the HTML file.
External2 CSS styles are written separately from the content in a style sheet in an external file. The HTML file links the style sheet.
Remarks
Examples
Shows how to work with CSS stylesheets that may be created along with Html documents.
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;
}
See Also