为什么在C#中将HTML文件转换为PDF时EO.PDF计时?

时间:2011-07-13 02:50:24

标签: c# html pdf c#-4.0

我有以下几段代码:

 public static void WriteHTML(string cFile, List<Movie> mList)
        {
            int lineID = 0;
            string strMovie, strGenre, tmpGenre = null;

            // initiates streamwriter for catalog output file
            FileStream fs = new FileStream(cFile, FileMode.Create);
            StreamWriter catalog = new StreamWriter(fs);

            string strHeader = "<style type=\"text/css\">\r\n" + "<!--\r\n" + "tr#odd {\r\n" + "    background-color:#e2e2e2;\r\n" + "  vertical-align:top;\r\n" + "}\r\n" + "\r\n" + "tr#even {\r\n" + "   vertical-align:top;\r\n" + "}\r\n" + "div#title {\r\n" + "  font-size:16px;\r\n" + "    font-weight:bold;\r\n" + "}\r\n" + "\r\n" + "div#mpaa {\r\n" + "    font-size:10px;\r\n" + "}\r\n" + "\r\n" + "div#genre {\r\n" + " font-size:12px;\r\n" + "    font-style:italic;\r\n" + "}\r\n" + "\r\n" + "div#plot {\r\n" + "   height: 63px;\r\n" + "  font-size:12px;\r\n" + "    overflow:hidden;\r\n" + "}\r\n" + "-->\r\n" + "</style>\r\n" + "\r\n" + "<html>\r\n" + "    <body>\r\n" + "     <table>\r\n";
            catalog.WriteLine(strHeader);

            foreach (Movie m in mList)
            {
                strMovie = lineID == 0 ? "          <tr id=\"odd\" style=\"page-break-inside:avoid\">" : "          <tr id=\"even\" style=\"page-break-inside:avoid\">";
                catalog.WriteLine(strMovie);

                foreach (string genre in m.Genres)
                    tmpGenre += ", " + genre;

                try
                { strGenre = tmpGenre.Substring(2); }
                catch (Exception)
                { strGenre = null; }

                strMovie = "                <td>\r\n" + "                   <img src=\".\\images\\" + m.ImageFile + "\" width=\"75\" height=\"110\">\r\n" + "               </td>\r\n" + "              <td>\r\n" + "                   <div id=\"title\">" + m.Title + "</div>\r\n" + "                    <div id=\"mpaa\">" + m.Certification + " " + m.MPAA + "</div>\r\n" + "                  <div id=\"genre\">" + strGenre + "</div>\r\n" + "                   <div id=\"plot\">" + m.Plot + "</div>\r\n" + "              </td>\r\n" + "          </tr>\r\n";
                catalog.WriteLine(strMovie);
                lineID = lineID == 0 ? 1 : 0;
            }

            catalog.WriteLine("     </table>\r\n" + "   </body>\r\n" + "</html>");
            catalog.Close();
        }




        public static void WritePDF(string cFile, string pdfFile)
        {
            // Sets up PDF to write to
            EO.Pdf.HtmlToPdf.Options.PageSize = new SizeF(8.5f, 11f);
            EO.Pdf.HtmlToPdf.Options.OutputArea = new RectangleF(0.5f, .25f, 7.5f, 10.25f);

            HtmlToPdf.ConvertUrl(cFile, pdfFile);
        }

我的HTML文件写得很好,但是当它试图将HTML文件转换为PDF时,我得到一个超时的例外。

我以前做了一个测试,并且让它在WriteHTML函数中转换代码(而不是文件)并且它工作得很好。我已经确认cFile存在并且是一个有效的文件(之前在WriteHTML中创建)。 pdfFile的路径是有效的,文档没有说明文件需要已经存在(.ConvertHTML不需要现有文件)。

我唯一能想到的是,catalog.html文件尚未发布并且尚未准备好阅读。我确保在WriteHTML函数中关闭它。如何测试文件是否可以读取?

尝试设置.MaxLoadWaitTime = 120000没有运气。

任何线索都会非常感激!

1 个答案:

答案 0 :(得分:0)

经过一系列的进一步测试和搜索EO支持论坛后,它似乎是免费版EO的限制。对于超过3MB的HTML文件似乎有困难。

令人遗憾的是,EO产品非常好,但不幸的是不值得250美元IMO。