将html转换为pdf时发生未处理的异常

时间:2016-02-25 11:42:19

标签: javascript winforms c#-4.0

我正在使用以下的coe来生成pdf格式的报告。当我在visual studio 2012中调试程序时,它不会产生任何异常。但是在使用installshield wizard 2012生成设置后,当我点击生成报告的按钮时pdf格式,它给出了错误,例如发生了Unhanded异常,它提供了继续选项或退出检查以下链接。

http://postimg.org/image/awk1ix6y7/

以下是我的类文件,它生成pdf报告。

public void generatereport(string date1,string date2,string product)
        {
            try
            {
                DateTime date11 = Convert.ToDateTime(date1);
                date111 = date11.ToString("f");
                DateTime date22 = Convert.ToDateTime(date2);
                date222 = date22.ToString("f");
                DateTime curdate = System.DateTime.Now;
                currentdate = curdate.ToString("f");
            }
            catch (Exception er)
            {
            }
            path = savefilepath();
            //mode = 2;
            mode = lo_setting.getmodeofdevices();
            getdataforgraph(date1, date2);
            if (dt1.Rows.Count > 0)
            {
                string imageurl = getimage();
                maxminavg();
                assignminmaxvalues();
                creategraphmeasures();
                reportclientdetails();
                reportequipmentdetails();
                htmlcode = "";
                htmlcode += "<!DOCTYPE html><html><head><title>jQuery bubble chart</title><script type='text/javascript' src='file:///C:/Program Files/HMG INDIA/HMG LOGGER APPLICATION/jquery1_11_1.js'></script> <script type='text/javascript' src='file:///C:/Program Files/HMG INDIA/HMG LOGGER APPLICATION/jquery.canvasjs.min.js'></script><script type='text/javascript'>";
                htmlcode += "\n" + "window.onload = function() {" + "\n";


                if (mode == 1)
                {
                    //div1 teperature chart1
                    htmlcode += "$('#chartContainer').CanvasJSChart({" + "\n";
                    htmlcode += "title: {" + "\n";
                    htmlcode += "text: 'Temperature "+Convert.ToString(dt10.Rows[0]["equip_name"])+"(" + min_date + " To " + max_date + ")'," + "\n";
                    htmlcode += "fontSize: 22}," + "\n";
                    htmlcode += "axisY: { title: '=> Temperature =>', includeZero: true, Prefix: '$' }, " + "\n";
                    htmlcode += "axisX: { interval: " + interval_xaxis + ", intervalType: 'Number', labelAngle: -45 }, " + "\n";
                    htmlcode += "axisX: { minimum: 0 }, " + "\n";
                    htmlcode += "axisY: { minimum: " + min_pt + "}, " + "\n";
                    htmlcode += "axisY: { maximum: " + max_pt + "}, " + "\n";

                    htmlcode += "data: [ { type: 'spline',toolTipContent: '{x}: {y} USD/gal',";

                    htmlcode += "\n" + "dataPoints: [ ";
                    for (int i = 0; i < dt3.Rows.Count; i++)
                    {
                        try
                        {
                            if (i == dt3.Rows.Count - 1)
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["pt"]) + "}";
                            else
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["pt"]) + "},";
                        }
                        catch (Exception er)
                        {
                        }

                    }
                    htmlcode += "]" + "\n" + "      } ] });";

                    //div2 relative humidity chart1
                    htmlcode += "$('#chartContainer1').CanvasJSChart({" + "\n";
                    htmlcode += "title: {" + "\n";
                    htmlcode += "text: 'Relative Humidity "+Convert.ToString(dt10.Rows[0]["equip_name"])+"(" + min_date + " To " + max_date + ")'," + "\n";
                    htmlcode += "fontSize: 22}," + "\n";
                    htmlcode += "axisY: { title: '=> Relative Humidity =>', includeZero: true, Prefix: '$' }, " + "\n";
                    htmlcode += "axisX: { interval: " + interval_xaxis + ", intervalType: 'Number', labelAngle: -45 }, " + "\n";
                    htmlcode += "axisX: { minimum: 0 }, " + "\n";
                    htmlcode += "axisY: { minimum: " + min_prh + "}, " + "\n";
                    //htmlcode += "axisY: { maximum: " + max_prh + "}, " + "\n";

                    htmlcode += "data: [ { type: 'spline',toolTipContent: '{x}: {y} USD/gal',";

                    htmlcode += "\n" + "dataPoints: [ ";
                    for (int i = 0; i < dt3.Rows.Count; i++)
                    {
                        try
                        {
                            //Convert.ToDouble(dt3.Rows[i]["time_diff"]), Convert.ToDouble(dt3.Rows[i]["prh"])
                            if (i == dt3.Rows.Count - 1)
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["prh"]) + "}";
                            else
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["prh"]) + "},";
                        }
                        catch (Exception er)
                        {
                        }

                    }
                    htmlcode += "]" + "\n" + "      } ] });";
                }

                if (mode == 2)
                {
                    //div3 relative humidity chart1
                    htmlcode += "$('#chartContainer2').CanvasJSChart({" + "\n";
                    htmlcode += "title: {" + "\n";
                    htmlcode += "text: 'Temperature "+Convert.ToString(dt10.Rows[1]["equip_name"])+"(" + min_date + " To " + max_date + ")'," + "\n";
                    htmlcode += "fontSize: 22}," + "\n";
                    htmlcode += "axisY: { title: '=> Temperature =>', includeZero: true, Prefix: '$' }, " + "\n";
                    htmlcode += "axisX: { interval: " + interval_xaxis + ", intervalType: 'Number', labelAngle: -45 }, " + "\n";
                    htmlcode += "axisX: { minimum: 0 }, " + "\n";
                    htmlcode += "axisY: { minimum: " + min_pt + "}, " + "\n";
                    htmlcode += "axisY: { maximum: " + max_pt + "}, " + "\n";

                    htmlcode += "data: [ { type: 'spline',toolTipContent: '{x}: {y} USD/gal',";

                    htmlcode += "\n" + "dataPoints: [ ";
                    for (int i = 0; i < dt3.Rows.Count; i++)
                    {
                        try
                        {
                            //Convert.ToDouble(dt3.Rows[i]["time_diff"]), Convert.ToDouble(dt3.Rows[i]["prh"])
                            if (i == dt3.Rows.Count - 1)
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["p1t"]) + "}";
                            else
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["p1t"]) + "},";
                        }
                        catch (Exception er)
                        {
                        }

                    }
                    htmlcode += "]" + "\n" + "      } ] });";

                    //div4 relative humidity chart1
                    htmlcode += "$('#chartContainer3').CanvasJSChart({" + "\n";
                    htmlcode += "title: {" + "\n";
                    htmlcode += "text: 'Relative Humidity "+Convert.ToString(dt10.Rows[1]["equip_name"])+"(" + min_date + " To " + max_date + ")'," + "\n";
                    htmlcode += "fontSize: 22}," + "\n";
                    htmlcode += "axisY: { title: '=> Relative Humidity =>', includeZero: true, Prefix: '$' }, " + "\n";
                    htmlcode += "axisX: { interval: " + interval_xaxis + ", intervalType: 'Number', labelAngle: -45 }, " + "\n";
                    htmlcode += "axisX: { minimum: 0 }, " + "\n";
                    htmlcode += "axisY: { minimum: " + min_prh + "}, " + "\n";
                    htmlcode += "axisY: { maximum: " + max_prh + "}, " + "\n";

                    htmlcode += "data: [ { type: 'spline',toolTipContent: '{x}: {y} USD/gal',";

                    htmlcode += "\n" + "dataPoints: [ ";
                    for (int i = 0; i < dt3.Rows.Count; i++)
                    {
                        try
                        {
                            //Convert.ToDouble(dt3.Rows[i]["time_diff"]), Convert.ToDouble(dt3.Rows[i]["prh"])
                            if (i == dt3.Rows.Count - 1)
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["p1rh"]) + "}";
                            else
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["p1rh"]) + "},";
                        }
                        catch (Exception er)
                        {
                        }

                    }
                    htmlcode += "]" + "\n" + "      } ] });";
                }
                if (mode == 3)
                {
                    //div1 teperature chart1
                    htmlcode += "$('#chartContainer').CanvasJSChart({" + "\n";
                    htmlcode += "title: {" + "\n";
                    htmlcode += "text: 'Temperature " + Convert.ToString(dt10.Rows[0]["equip_name"]) + "(" + min_date + " To " + max_date + ")'," + "\n";
                    htmlcode += "fontSize: 22}," + "\n";
                    htmlcode += "axisY: { title: '=> Temperature =>', includeZero: true, Prefix: '$' }, " + "\n";
                    htmlcode += "axisX: { interval: " + interval_xaxis + ", intervalType: 'Number', labelAngle: -45 }, " + "\n";
                    htmlcode += "axisX: { minimum: 0 }, " + "\n";
                    htmlcode += "axisY: { minimum: " + min_pt + "}, " + "\n";
                    htmlcode += "axisY: { maximum: " + max_pt + "}, " + "\n";

                    htmlcode += "data: [ { type: 'spline',toolTipContent: '{x}: {y} USD/gal',";

                    htmlcode += "\n" + "dataPoints: [ ";
                    for (int i = 0; i < dt3.Rows.Count; i++)
                    {
                        try
                        {
                            if (i == dt3.Rows.Count - 1)
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["pt"]) + "}";
                            else
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["pt"]) + "},";
                        }
                        catch (Exception er)
                        {
                        }
                    }
                    htmlcode += "]" + "\n" + "      } ] });";

                    //div2 relative humidity chart1
                    htmlcode += "$('#chartContainer1').CanvasJSChart({" + "\n";
                    htmlcode += "title: {" + "\n";
                    htmlcode += "text: 'Relative Humidity " + Convert.ToString(dt10.Rows[0]["equip_name"]) + "(" + min_date + " To " + max_date + ")'," + "\n";
                    htmlcode += "fontSize: 22}," + "\n";
                    htmlcode += "axisY: { title: '=> Temperature =>', includeZero: true, Prefix: '$' }, " + "\n";
                    htmlcode += "axisX: { interval: " + interval_xaxis + ", intervalType: 'Number', labelAngle: -45 }, " + "\n";
                    htmlcode += "axisX: { minimum: 0 }, " + "\n";
                    htmlcode += "axisY: { minimum: " + min_prh + "}, " + "\n";
                    htmlcode += "axisY: { maximum: " + max_prh + "}, " + "\n";

                    htmlcode += "data: [ { type: 'spline',toolTipContent: '{x}: {y} USD/gal',";

                    htmlcode += "\n" + "dataPoints: [ ";
                    for (int i = 0; i < dt3.Rows.Count; i++)
                    {
                        try
                        {
                            //Convert.ToDouble(dt3.Rows[i]["time_diff"]), Convert.ToDouble(dt3.Rows[i]["prh"])
                            if (i == dt3.Rows.Count - 1)
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["prh"]) + "}";
                            else
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["prh"]) + "},";
                        }
                        catch (Exception er)
                        {
                        }

                    }
                    htmlcode += "]" + "\n" + "      } ] });";


                    //div3 relative humidity chart1
                    htmlcode += "$('#chartContainer2').CanvasJSChart({" + "\n";
                    htmlcode += "title: {" + "\n";
                    htmlcode += "text: 'Temperature " + Convert.ToString(dt10.Rows[1]["equip_name"]) + "(" + min_date + " To " + max_date + ")'," + "\n";
                    htmlcode += "fontSize: 22}," + "\n";
                    htmlcode += "axisY: { title: '=> Temperature =>', includeZero: true, Prefix: '$' }, " + "\n";
                    htmlcode += "axisX: { interval: " + interval_xaxis + ", intervalType: 'Number', labelAngle: -45 }, " + "\n";
                    htmlcode += "axisX: { minimum: 0 }, " + "\n";
                    htmlcode += "axisY: { minimum: " + min_p1t + "}, " + "\n";
                    htmlcode += "axisY: { maximum: " + max_p1t + "}, " + "\n";

                    htmlcode += "data: [ { type: 'spline',toolTipContent: '{x}: {y} USD/gal',";

                    htmlcode += "\n" + "dataPoints: [ ";
                    for (int i = 0; i < dt3.Rows.Count; i++)
                    {
                        try
                        {
                            //Convert.ToDouble(dt3.Rows[i]["time_diff"]), Convert.ToDouble(dt3.Rows[i]["prh"])
                            if (i == dt3.Rows.Count - 1)
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["p1t"]) + "}";
                            else
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["p1t"]) + "},";
                        }
                        catch (Exception er)
                        {
                        }

                    }
                    htmlcode += "]" + "\n" + "      } ] });";

                    //div4 relative humidity chart1
                    htmlcode += "$('#chartContainer3').CanvasJSChart({" + "\n";
                    htmlcode += "title: {" + "\n";
                    htmlcode += "text: 'Relative Humidity " + Convert.ToString(dt10.Rows[1]["equip_name"]) + "(" + min_date + " To " + max_date + ")'," + "\n";
                    htmlcode += "fontSize: 22}," + "\n";
                    htmlcode += "axisY: { title: '=> Relative Humidity =>', includeZero: true, Prefix: '$' }, " + "\n";
                    htmlcode += "axisX: { interval: " + interval_xaxis + ", intervalType: 'Number', labelAngle: -45 }, " + "\n";
                    htmlcode += "axisX: { minimum: 0 }, " + "\n";
                    htmlcode += "axisY: { minimum: " + min_p1rh + "}, " + "\n";
                    htmlcode += "axisY: { maximum: " + max_p1rh + "}, " + "\n";

                    htmlcode += "data: [ { type: 'spline',toolTipContent: '{x}: {y} USD/gal',";

                    htmlcode += "\n" + "dataPoints: [ ";
                    for (int i = 0; i < dt3.Rows.Count; i++)
                    {
                        try
                        {
                            //Convert.ToDouble(dt3.Rows[i]["time_diff"]), Convert.ToDouble(dt3.Rows[i]["prh"])
                            if (i == dt3.Rows.Count - 1)
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["p1rh"]) + "}";
                            else
                                htmlcode += "\n" + " {x: " + Convert.ToDouble(dt3.Rows[i]["time_diff"]) + ", y: " + Convert.ToDouble(dt3.Rows[i]["p1rh"]) + "},";
                        }
                        catch (Exception er)
                        {
                        }

                    }
                    htmlcode += "]" + "\n" + "      } ] });";  

                }
                htmlcode += "}";
                htmlcode +="\n"+ "</script></head><body>";
                try
                {
                    firstdiv_of_details = "<div style=' float:left;'><img src='file:///C:/Program Files/HMG INDIA/HMG LOGGER APPLICATION/Images/" + imageurl + "' style='height: 76px; width: 104px'/></div><h2 style='color: #008080; font-family: Verdana, Geneva, Tahoma, sans-serif; text-align: center;'>LOGGER REPORT</h2><br/><div></br>";
                    firstdiv_of_details += "<table style='width:100%; font-family: Verdana, Geneva, Tahoma, sans-serif; font-weight: bold; text-transform: capitalize; color: #000000'><tr><td colspan='3'></td></tr><tr> <td colspan='2'></td><td><b>Client Name: " + Convert.ToString(dt9.Rows[0]["company"]) + "</b></td><td></td></tr><tr><td></td><td></td><td><b>Location: " + Convert.ToString(dt9.Rows[0]["location"]) + "</b></td><td></td></tr><tr><td colspan='2'><b>Equipment Name : " + equipname + "</b></td><td colspan='2'><b>Equipment Make :" + equipmake + " </b></td></tr><tr><td>Equipment ID : " + equipid + "</td><td>Equipment Sr. No. : " + equipserialnumber + "</td><td>Logger ID :</td><td></td></tr><tr><td>Login ID :" + Convert.ToString(dbconnection.sess1) + "  </td><td>Login Date & Time :</td><td>Product Name : " + product + "</td><td></td></tr><tr><td>From Date & Time  : " + date111 + " </td><td>To Date & Time : " + date222 + " </td><td>Report Date & Time : " + currentdate + "</td><td></td></tr></table></br></br>";
                }
                catch (Exception er)
                {
                }
                htmlcode = htmlcode + firstdiv_of_details;

                if (mode == 1)
                {
                    htmlcodelast = htmlcode + "\n" + "<div id='chartContainer' style='width: 100%; height: 300px'></div>";
                    htmlcodelast += "</br></br><div id='chartContainer1' style='width: 100%; height: 300px'></div></br></br>";
                    //htmlcodelast1 = "</body></html>";
                    //htmlcodelast = htmlcodelast + htmlcodelast1;
                }
                if (mode == 2)
                {
                    htmlcodelast = htmlcode + "\n" + "</script></head><body><div id='chartContainer2' style='width: 100%; height: 300px'></div>";
                    htmlcodelast += "</br></br><div id='chartContainer3' style='width: 100%; height: 300px'></div></br></br>";
                    //htmlcodelast1 = "</body></html>";
                    //htmlcodelast = htmlcodelast + htmlcodelast1;
                }
                if (mode == 3)
                {
                    htmlcodelast = htmlcode + "\n" + "</script></head><body><div id='chartContainer' style='width: 100%; height: 300px'></div>";
                    htmlcodelast += "</br></br><div id='chartContainer1' style='width: 100%; height: 300px'></div>";

                    htmlcodelast +="</script></head><body><div id='chartContainer2' style='width: 100%; height: 300px'></div>";
                    htmlcodelast += "</br></br><div id='chartContainer3' style='width: 100%; height: 300px'></div></br></br>";
                    //htmlcodelast1 = "</body></html>";
                    //htmlcodelast = htmlcodelast + htmlcodelast1;
                }

                int type = getusersignature();
                string signaturetable = "";
                try
                {
                    if (type == 0)
                    {
                        signaturetable += "</br></br><table width='100%'><tr><td></td><td></td><td align='center'>" + Convert.ToString(dt3.Rows[0][0]) + "</td></tr><tr style='text-align:center;'><td>Prepared By</td><td>Approved By</td><td>Electronic Signature</td></tr></table>";
                    }
                    else
                    {
                        signaturetable += "</br></br><table width='100%'><tr><td></td><td></td><td align='center'><img src='file:///C:/Program Files/HMG INDIA/HMG LOGGER APPLICATION/Images/" + Convert.ToString(dt3.Rows[0][0]) + "' style='height: 76px; width: 104px'/></td></tr><tr style='text-align:center;'><td>Prepared By</td><td>Approved By</td><td>Electronic Signature</td></tr></table>";
                    }
                }
                catch (Exception er)
                {
                }

                htmlcodelast = htmlcodelast+signaturetable+htmlcodelast1;

                string baseUrl = "";
                string pdf_page_size = "A4";
                PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize),
                    pdf_page_size, true);

                string pdf_orientation = "Portrait";
                PdfPageOrientation pdfOrientation =
                    (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation),
                    pdf_orientation, true);

                int webPageWidth = 1024;


                int webPageHeight = 0;
                HtmlToPdf converter = new HtmlToPdf();
                converter.Options.PdfPageSize = pageSize;
                converter.Options.PdfPageOrientation = pdfOrientation;
                converter.Options.WebPageWidth = webPageWidth;
                converter.Options.WebPageHeight = webPageHeight;

                converter.Options.MinPageLoadTime = 2;
                converter.Options.MaxPageLoadTime = 30;
                PdfDocument doc = converter.ConvertHtmlString(htmlcodelast, baseUrl);
                doc.Save(path+ ".pdf");
                doc.Close();
            }
            else
            {
                MessageBox.Show("There are no records for creating graph in this interval of time.");
            }
        }

这是给出的错误:

  

System.Exception:转换失败。找不到'Select.Html.dep'。在SelectPdf.HtmlToImage。ᜀ(String A_0,String A_1,   字符串A_2,᥹[]&amp; A_3,ᥖ&amp; A_4)在SelectPdf.HtmlToPdf。ᜀ(字符串A_0,   字符串A_1,字符串A_2,字符串A_3,布尔A_4)at   SelectPdf.HtmlToPdf.ConvertHtmlString(String htmlString,String   的baseUrl)。我在Windows窗体应用程序中使用此代码

0 个答案:

没有答案