如何使用c在pdf iTextSharp中执行JavaScript代码#
我一直在Visual Studio 2012中开发一个MVC应用程序ASP.NET(C#)。我想在我的pdf文档中使用Highchart图表,该文档是我使用iTextSharp(c#)创建的。对于Highchart图表,我使用了一些JavaScript代码。我想执行此JavaScript代码并将其包含在我的pdf(iTextSharp)文档中。我在c#中使用的代码是:如何使用c在pdf iTextSharp中执行JavaScript代码#,javascript,c#,asp.net,pdf,highcharts,Javascript,C#,Asp.net,Pdf,Highcharts,我一直在Visual Studio 2012中开发一个MVC应用程序ASP.NET(C#)。我想在我的pdf文档中使用Highchart图表,该文档是我使用iTextSharp(c#)创建的。对于Highchart图表,我使用了一些JavaScript代码。我想执行此JavaScript代码并将其包含在我的pdf(iTextSharp)文档中。我在c#中使用的代码是: StringBuilder示例_html3=新建StringBuilder(); 示例_html3.Append(@“Highc
StringBuilder示例_html3=新建StringBuilder();
示例_html3.Append(@“Highcharts.chart”(“container”);
示例_html3.Append(@“chart:{”);
示例_html3.Append(@“type:“boxplot”);
示例_html3.Append(@“},”);
示例_html3.Append(@“title:{”);
示例_html3.Append(@“文本:”“所有患者”);
示例_html3.Append(@“},”);
示例_html3.Append(@“legend:{”);
示例_html3.Append(@“enabled:false”);
示例_html3.Append(@“},”);
示例_html3.Append(@“xAxis:{”);
示例3.Append(@“类别:[“亚太”、“欧洲”、“拉丁美洲”、“北美”、“西南非洲”],”);
示例_html3.Append(@“title:{”);
示例_html3.Append(@“text:“”);
示例_html3.Append(@“}”);
示例_html3.Append(@“},”);
示例_html3.Append(@“yAxis:{”);
示例_html3.Append(@“title:{”);
示例\u html3.追加(@“文本:”“2016年度中心卷”);
示例_html3.Append(@“},”);
示例_html3.Append(@“min:0”);
示例_html3.Append(@“},”);
示例_html3.Append(@“series:[{”);
示例_html3.Append(@“名称:”“区域运行”“);
示例3.Append(@“data:[”);
示例3.Append(@“[1,4,18,43,74],”);
示例3.Append(@“[1,9,16.5,32,62],”);
示例3.Append(@“[1,3,6,11.5,22],”);
示例3.Append(@“[1,9,20,38,81],”);
示例3.Append(@“[1,2,8,16,23]”);
示例_html3.Append(@“,”);
示例_html3.Append(@“工具提示:{”);
示例_html3.Append(@“headerFormat:”实验编号{point.key}
“”);
示例_html3.Append(@“}”);
示例_html3.Append(@“},{”);
示例_html3.Append(@“name:”Outlier“”);
示例_html3.Append(@“color:Highcharts.getOptions().colors[0],”);
示例_html3.Append(@“type:“scatter”“”);
示例_html3.Append(@“数据:[//x,y位置,其中0是第一类”);
示例_html3.Append(@“[0,128]”);
示例_html3.追加(@“[161],”);
示例3.Append(@“[2,58],”);
示例_html3.Append(@“[3204],”);
示例3.Append(@“[4,42]”);
示例_html3.Append(@“,”);
示例_html3.Append(@“marker:{”);
示例_html3.Append(@“fillColor:”白色“);
示例3.Append(@“线宽:1,”);
示例_html3.Append(@“lineColor:Highcharts.getOptions().colors[0]”);
示例_html3.Append(@“},”);
示例_html3.Append(@“工具提示:{”);
示例_html3.Append(@“pointFormat:”Observation:{point.y}“”);
示例_html3.Append(@“}”);
示例_html3.Append(@“}]”);
示例_html3.Append(@“})”;
字符串示例_html31=示例_html3.ToString();
pdproduction-jaction=pdproduction.JavaScript(示例html31,编写器);
AddJavaScript(jaction);
但是,我的pdf没有显示图表。你知道怎么解决这个问题吗?提前感谢您的帮助。iText支持静态XML的某个子集,但不执行JavaScript。因此,您需要一些其他组件来加载HTML,执行JavaScript代码,然后允许检索完成的图表。不过,我不确定HighChart生成的HTML是否受iText支持。感谢@mkl对您的兴趣和帮助。
StringBuilder example_html3 = new StringBuilder();
example_html3.Append(@"Highcharts.chart(""container"", {");
example_html3.Append(@"chart: {");
example_html3.Append(@" type: ""boxplot""");
example_html3.Append(@"},");
example_html3.Append(@"title: {");
example_html3.Append(@" text: ""All Patients""");
example_html3.Append(@"},");
example_html3.Append(@"legend: {");
example_html3.Append(@" enabled: false");
example_html3.Append(@"},");
example_html3.Append(@"xAxis: {");
example_html3.Append(@"categories: [""Asia Pacific"", ""Europe"", ""Latin Am"", ""North Am"", ""SWAC""],");
example_html3.Append(@"title: {");
example_html3.Append(@" text: "" """);
example_html3.Append(@"}");
example_html3.Append(@"},");
example_html3.Append(@"yAxis: {");
example_html3.Append(@"title: {");
example_html3.Append(@" text: ""Annual Center Volume 2016""");
example_html3.Append(@"},");
example_html3.Append(@"min: 0");
example_html3.Append(@"},");
example_html3.Append(@"series: [{");
example_html3.Append(@"name: ""Region Runs"",");
example_html3.Append(@"data: [");
example_html3.Append(@"[1, 4, 18, 43, 74], ");
example_html3.Append(@"[1, 9, 16.5, 32, 62], ");
example_html3.Append(@"[1, 3, 6, 11.5, 22], ");
example_html3.Append(@"[1, 9, 20, 38, 81], ");
example_html3.Append(@"[1, 2, 8, 16, 23]");
example_html3.Append(@"],");
example_html3.Append(@"tooltip: {");
example_html3.Append(@"headerFormat: ""<em>Experiment No {point.key}</em><br/>""");
example_html3.Append(@"}");
example_html3.Append(@"}, {");
example_html3.Append(@"name: ""Outlier"",");
example_html3.Append(@"color: Highcharts.getOptions().colors[0],");
example_html3.Append(@"type: ""scatter"",");
example_html3.Append(@"data: [ // x, y positions where 0 is the first category");
example_html3.Append(@"[0, 128], ");
example_html3.Append(@"[1, 161], ");
example_html3.Append(@"[2, 58], ");
example_html3.Append(@"[3, 204], ");
example_html3.Append(@"[4,42] ");
example_html3.Append(@"],");
example_html3.Append(@"marker: {");
example_html3.Append(@" fillColor: ""white"",");
example_html3.Append(@" lineWidth: 1,");
example_html3.Append(@" lineColor: Highcharts.getOptions().colors[0] ");
example_html3.Append(@"},");
example_html3.Append(@"tooltip: {");
example_html3.Append(@" pointFormat: ""Observation: {point.y}""");
example_html3.Append(@"}");
example_html3.Append(@"}]");
example_html3.Append(@"})");
string example_html31 = example_html3.ToString();
PdfAction jaction = PdfAction.JavaScript(example_html31, writer);
writer.AddJavaScript(jaction);