Hi,
Below are the HTML template and the .Net 8 code we are using to render and convert the HTML.
The Javascript output is not reflected in the image - I believe it is not being executed. The output PNG is attached.
How can we make it work?
Am running this on a Windows machine, but plan to deploy it in AWS EKS using a Linux based image.
<!DOCTYPE html>
<html>
<head>
<title>Organization Chart</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gojs/2.1.55/go.js"></script>
<style>
#myDiagramDiv {
width: 200px;
height: 200px;
border: 1px solid black;
}
</style>
</head>
<body>
<div id="myDiagramDiv"></div>
<textarea id="imageData"></textarea>
<script>
var $ = go.GraphObject.make;
var myDiagram = $(go.Diagram, "myDiagramDiv",
{
"undoManager.isEnabled": true
});
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape, "RoundedRectangle",
{ strokeWidth: 0 },
new go.Binding("fill", "color")),
$(go.TextBlock,
{ margin: 8 },
new go.Binding("text", "name"))
);
myDiagram.model = new go.GraphLinksModel(
[ // a JavaScript Array of JavaScript objects, one per node;
// the "color" property is added specifically for this app
{ key: 1, text: "Alpha", color: "lightblue" },
{ key: 2, text: "Beta", color: "orange" },
{ key: 3, text: "Gamma", color: "lightgreen" },
{ key: 4, text: "Delta", color: "pink" }
],
[ // a JavaScript Array of JavaScript objects, one per link
{ from: 1, to: 2 },
{ from: 1, to: 3 },
{ from: 2, to: 2 },
{ from: 3, to: 4 },
{ from: 4, to: 1 }
]);
var imageData = myDiagram.makeImageData({
scale: 1,
maxSize: new go.Size(Infinity, Infinity)
});
document.getElementById('imageData').value = imageData;
</script>
</body>
</html>
public string CreateUsingAspose()
{
var sw = new Stopwatch();
var result = string.Empty;
try
{
using var config = new Configuration();
config.Security = Sandbox.None;
var runtimeService = config.GetService<IRuntimeService>();
runtimeService.JavaScriptTimeout = TimeSpan.FromSeconds(20);
using var doc = new HTMLDocument(@"Templates/GoJs.html", config);
var imageDataElement = doc.GetElementById("imageData");
var htmlTextAreaElement = (HTMLTextAreaElement)imageDataElement;
result = htmlTextAreaElement?.Value ?? string.Empty;
using HtmlRenderer renderer = new HtmlRenderer();
using ImageDevice device = new ImageDevice("output.png");
renderer.Render(device, doc, TimeSpan.FromSeconds(20));
}
catch (Exception ex)
{
}
return result;
}
output.png (49.5 KB)