Hii Team,
I am converting HTML to word by using Aspose.words. For that, I am going to inject a style sheet for the document.
//this method is used to inject the style sheet
private HtmlDocument AddCssLinks(IDictionary<string, string> options, HtmlDocument htmlDocument)
{
if (options.TryGetValue(ContentsConstants.CONVERT_OPT_CSS, out string cssReference))
{
var links = cssReference.Split(',', '|');
var linknode = htmlDocument.CreateElement("link");
linknode.SetAttributeValue("href", links[0]);
linknode.SetAttributeValue("rel", "stylesheet");
var htmlHead = htmlDocument.DocumentNode.SelectSingleNode("//head");
htmlHead.AppendChild(linknode);
}
return htmlDocument;
}
//this is my main method ,which is used to call the above method.
public List<byte[]> Convert(ContentsDto content, IDictionary<string, string> options, System.Func<DependentContent, Task<ContentsDto>> GetDependency = null)
{
//TODO:load license from application startup
License htmlLicense1 = new License();
htmlLicense1.SetLicense("Aspose.Words.NET.lic");
var byteArray = new List<byte[]>();
using (var dataStream = new MemoryStream(content.Data))
{
HtmlLoadOptions docOptions = new HtmlLoadOptions
{
ResourceLoadingCallback = new AsposeWordsAuthHandler(_settingsProvider, _authSettings, _logger)
};
var document = new Aspose.Words.Document(dataStream, docOptions);
using (var outputStream = new MemoryStream())
{
HtmlDocument htmlDocument = new HtmlDocument();
using (var htmlStream = new MemoryStream(content.Data))
{
htmlDocument.Load(htmlStream);
}
SetImageLayout(document, htmlDocument);
SetupHeader(document, GetDependency);
SetupFooter(document);
// AddCssLinks Method
var modifiedHTML = AddCssLinks(options, htmlDocument);
//
document.Save(outputStream, SaveFormat.Docx);
Document doc2 = new Document(outputStream);
using (var outputStream2 = new MemoryStream())
{
SetImageMargins(doc2);
doc2.Save(outputStream2, SaveFormat.Docx);
byteArray.Add(outputStream2.ToArray());
}
}
}
return byteArray;
}
this is not working. Do I need to convert returned HTML in the first method to the document??? How Can I further process that method in the main method???