Hi Support,
How i can call JavaSript function from HTMLDocument OnShow Event?
Here’s example of my code and event:
public static Stream ConvertTablesToImages(Stream xhtml, string publicationName)
{
try
{
using (var document = new HTMLDocument(xhtml, String.Empty))
{
var tableContainers = document.GetElementsByTagName("table")
.Where(e => e.GetAttributeNode("class").Value == "table")
.Select(node => node.ParentElement)
.ToList();
if(tableContainers == null || !tableContainers.Any())
{
return xhtml;
}
int tablePosition = 0;
logger.Debug("Tables conversion started for - '" + publicationName + "'");
foreach (var tableContainer in tableContainers)
{
try
{
tablePosition++;
logger.Debug("Table conversion at [" + tablePosition + "] postion started");
var table = tableContainer.Children.First(elm => elm.LocalName == "table");
using (var streamProvider = new MemoryStreamProvider())
{
Stream imageStream;
using (var tableDocument = new HTMLDocument(WrapTable(table.OuterHTML), String.Empty))
{
AttachCSS(tableDocument);
Converter.ConvertHTML(tableDocument, saveOptions, streamProvider);
imageStream = streamProvider.ImageStream;
}
var tableImage = document.CreateElement("img");
tableImage.SetAttribute("class", "image");
tableImage.SetAttribute("src", "data:image/png;base64," + ConvertToBase64String(imageStream) + "");
tableContainer.RemoveChild(table);
tableContainer.AppendChild(tableImage);
}
//logger.Debug("Table conversion at [" + tablePosition + "] postion finished");
}
catch(System.Exception ex)
{
logger.Error("Table conversion error for table at " + tablePosition + " position with error: \n", ex);
continue;
}
}
logger.Debug("Tables conversion finished for - '" + publicationName + "'");
document.OnShow += (object sender, Event e) =>
{
//here i need call JavaScript function which included into HTMLDocument
};
MemoryOutputStorage memoryOutputStorage = new MemoryOutputStorage();
//save document to MemoryStream
document.Save(memoryOutputStorage, HTMLSaveFormat.Original);
xhtml.Dispose();
return memoryOutputStorage.DocumentStream;
}
}
catch (System.Exception ex)
{
logger.Error("Tables conversion error for publication - '" + publicationName + ": \n", ex);
return xhtml;
}
}