开发者

Generate PDF from a page with highcharts on it with abcpdf

We use ABCPDF to convert a HTMl page to a PDF. Everything works fine, except the charts generated with highcharts.The usescript tag is set to true, but the area where the chars is rendered stays empty. In IE9 the charts is rendered. anyone knows a solution?

        Doc theDoc = new Doc();
        theDoc.HtmlOptions.UseScript = true;
        theDoc.HtmlOptions.I开发者_如何学JAVAmageQuality = 100;          

        theDoc.AddImageUrl("/factsheet.html", false, 984, true);

        byte[] theData = theDoc.GetData();
        Response.Clear();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "inline; filename=MyPDF.PDF");
        Response.AddHeader("content-length", theData.Length.ToString());
        Response.BinaryWrite(theData);
        Response.End();


This issue can be caused by animated graphics that dynamically fade in.

ABCpdf will attempt to capture a page as soon as it has finished loading. So, if the initial state of the chart is blank, this is how it will appear in the rendered PDF document.

To get the Highchart graphics to display properly you may need to delay the rendering slightly. You can achieve this by specifying Gecko as the HTML rendering engine, and setting a delay via the HtmlOptions.OnloadScript property, something like:

Doc doc = new Doc();
doc.HtmlOptions.Engine = HTMLEngineType.Gecko;
doc.HtmlOptions.UseScript = true;
doc.HtmlOptions.OnLoadScript = "(function(){window.ABCpdf_go = false; setTimeout(function(){window.ABCpdf_go = true;}, 1000);})();";
doc.AddImageUrl("http://example.com/");
doc.Save("example.pdf");

In the example above, JavaScript is assigned to the HtmlOptions.OnLoadScript property, which will run client-side, setting the 'window.ABCpdf_go' property to 'true' after 1 second.

ABCpdf will wait for window.ABCpdf_go to become 'true' or 'undefined' before rendering any HTML. ABCpdf will stop watching if the HtmlOptions.Timeout is exceeded.

The window.ABCpdf_go property is a recent addition to ABCpdf, so check you're working with the latest version.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜