Free Support Forum - aspose.com

CssSavingCallback

Hi,

I'd like to get hold of the css that's generated when converting a word document to HTML. I've managed to convert the document to html and get the CSS generated into an external css file with no problem.

However, what I'd like to know is if I can get hold of the css text on the server before it's outputted to the css document? It looks as though I might be able to by implementing ICssSavingCallback interface. But the CssSavingArgs.CssStream is always null when I implement it? Any ideas? Here is my code:

public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Document doc = new Document(Server.MapPath("/SampleAspose.docx"));
HtmlSaveOptions opts = new HtmlSaveOptions(SaveFormat.Html);
opts.CssStyleSheetType = CssStyleSheetType.External;
//opts.CssStyleSheetFileName = Server.MapPath("/Output/SampleAsposeCSS.css");
GetCss callback = new GetCss();
opts.CssSavingCallback = callback;
doc.Save(Server.MapPath("/Output/SampleAspose.html"), opts);
}
}

public class GetCss : ICssSavingCallback
{
public void CssSaving(CssSavingArgs args)
{
CssSavingArgs myArgs = args;
}
}

Any ideas on this support guys?

Hi Kevin,


Thanks for your inquiry. Yes, you’re right; CssSavingArgs.CssStream is always returning a Null value. I am in communication with our development team. I will update you as soon as I have extra information on this.

PS: CssSavingArgs.CssStream allows you to save CSS information to a stream. The default value is null. However, 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.

Best regards,

Thank you for the update

I found that P.S. paragraph in the documentation but it doesn't really make sense. If you can show me a working example of the CssStream being populated, it would be greatly appreciated.

Also, I've tried loading the document into a memory stream instantiating the aspose Document object with the stream, but that doesn't work either.

Thank you for your help on this - looking forward to a resolution.

Hi Kevin,


Thanks for the additional information. Sure, I will keep you informed of any updates I receive from the concerned developer.

Best regards,
Hi Kevin,
Kevin:

I found that P.S. paragraph in the documentation but it doesn't really make sense. If you can show me a working example of the CssStream being populated, it would be greatly appreciated.

Thanks for your patience. This property allows to specify the stream where the CSS information will be saved to. Please find below the sample usage:

Document doc = new Document(@"C:\temp\input.docx");

HtmlSaveOptions opts = new HtmlSaveOptions(SaveFormat.Html);

opts.CssStyleSheetType = CssStyleSheetType.External;

opts.CssStyleSheetFileName = @"C:\Temp\myCSS.css";

opts.CssSavingCallback = new HandleCss();

doc.Save(@"C:\Temp\out.html", opts);

public class HandleCss : ICssSavingCallback

{

public void CssSaving(CssSavingArgs args)

{

args.CssStream = new FileStream(@"C:\Temp\myCSS1.css",FileMode.CreateNew);

}

}


If we can help you with anything else, please feel free to ask.

Best regards,