CssSavingArgsKeepCssStreamOpen Property |
Namespace: Aspose.Words.Saving
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.
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; }