我在使用itextsharp生成pdf时遇到异常。 这里html只在代码后面编写。将它作为html流式阅读器
我试过以下
Response.ContentType = "text/html";
StringBuilder sb = new StringBuilder();
sb.Append("<!DOCTYPE html><html><head><title></title></head><body><div style = 'font-family: Arial, Helvetica, sans-serif; font-size: 18px; line-height: 22px; padding:50px 20px; color: #333; width: 900px; margin: 0 auto;text-align: justify;'>");
sb.Append(string.Format("<div style='padding: 0 0 20px 0;'><a style = 'float: left; width: 226px;' href = '#' ><img style = 'width: 100%; height: auto;' alt = 'logo' src = 'http://dev.cdn.bbyo.org/bbyodevblob/bbyo/media/bbyo/images/bbyo_logo_color.png'></img></a><span style = 'float: right;width: 60%;padding-top: 32px;display: block;text-align: right;' > Membership Enrollment Agreement, Waiver and Release </span><div style = 'clear: both;'></div></div><p style ='padding:0 0 15px 0; margin: 0;' > I, <span> {0} </span>, (“Participant”) hereby request that BBYO allow me to participate in BBYO’s Programs (“Programs”), as a Member of BBYO, Inc.I agree to abide by the conditions of participation set forth in the BBYO Code of Conduct and in other documents, policies and procedures that may be provided by BBYO to me. I further understand the risks associated with participation in all activities including but not limited to overnight stays, transportation and travel to/ from events, sports activities, etc. I acknowledge that the nature of programs and current events may expose me to increased health and safety risk at times and that if programs are held in remote locations, access to medical facilities may not meet the standards to which I am accustomed.</p>", "gopi krishna"));
sb.Append("<p style = 'padding-bottom: 15px; margin: 0;'> I understand and accept the risks associated with my participation in all BBYO programs and <strong> fully and unconditionally release and forever discharge</strong> BBYO, Inc., its travel partner Tlalim, and each of their respective affiliated entities, directors, officers, employees, and all of their respective successors and assigns, from any and all liability to me, my family and my personal representatives, including heirs, successors and assigns.I accept responsibility for all injuries, damages, loss and liability, and the consequences thereof, occurring in connection with and / or in any way related to my participation in the Programs at any time after the execution of this Agreement.</p><br/><div><ul><li style = 'margin: 0; margin-bottom: 15px;'>I agree that BBYO is not responsible or liable for any injury, damage, loss, costs, refunds, expense, accident, delay, scheduling changes, cancellation or other irregularity which may be caused by third party travel agents / organizations or the transportation carriers or other companies or persons engaged in providing or performing any of the services involved in the Programs or that may otherwise occur during the Programs.</li>");
sb.Append("<li style = 'margin: 0; margin-bottom: 15px;'>I understand and agree that I will be required to pay for any incidental personal expenses that I incur while participating in the Programs, as well as for any damage I cause to property of others.</li><li style = 'margin: 0; margin-bottom: 15px;'>I agree that, if I become ill or incapacitated, BBYO may take any action it deems necessary for my safety and well - being, including securing medical treatment(at my own expense) and making arrangements for transporting me home or to any medical facility, as the case may call for. I understand that in such instances I will not be entitled to any refund of paid Program fees or costs and that all travel arrangements, costs and liabilities associated with being sent home or to a medical facility will be the sole responsibility of me and my parent(s) / legal guardian(s).</li><li style = 'margin: 0; margin-bottom: 15px;'>I agree to abide by the directions of BBYO staff as well as the BBYO Code of Conduct, transportation policies, housing and living - arrangement policies, substance - abuse policies, and such other policies and guidelines that may apply.I understand that m time to time program rules may be modified by BBYO in its sole discretion, without prior notice.");
sb.Append("</li><li style = 'margin: 0; margin-bottom: 15px;'>I understand and agree that I am required to comply with the current laws of the United States, its states, territories and municipalities, and the laws of those countries in which the Programs I participate in take place.I understand and agree that my failure to do so may result in discipline, including the immediate termination of my participation in the Programs, including but not limited to being immediately sent home from such Programs, and / or immediate dismissal from membership, as determined in the sole discretion of BBYO.I further understand and agree that BBYO, as it deems appropriate in its sole discretion, has the right but not the obligation to search my person and/ or belongings and to take such action (or to refrain from such action) at it deems appropriate to secure the safety of me and / or others and/ or to ensure compliance with BBYO Code of Conduct, transportation policies, housing and living arrangement policies and other policies and guidelines, including but not limited to dismissal from membership and/ or participation in the Programs.</li><li style = 'margin: 0; margin-bottom: 15px;'>I understand and agree that in the event I am expelled from a Program, I will not be entitled");
sb.Append(" to any refund of paid Program fees or costs and that all travel arrangements, costs and liabilities(including but not limited to escort costs, if applicable) associated with being sent home will be the sole responsibility of me and my parent(s)/legal guardian(s), and that such fees or costs may need to be paid up front In the event I am expelled from a program, I understand and agree that BBYO reserves the right to make travel arrangements for my return to the original gateway(airport) city and to place me on a flight as an unaccompanied minor, unless other arrangements, satisfactory to BBYO, are made with my parent(s)/legal guardian(s).</li></ul></div><div class=''><h4 style = 'font-style: normal;font-weight: 400; display: inline-block; text-decoration: underline; font-size: 16px; margin: 0; padding-bottom: 15px;'> Authorization to Take/Publish Photographs and Videos</h4><p style = 'padding-bottom: 15px; margin: 0;'> I hereby authorize BBYO to take and/or publish photographs/video/quotations taken of me (including printing or otherwise publishing my name in association with such photograph/video or quotation) in printed or electronic format, including but not limited to in publications, presentations, promotions(including those which are mailed),");
sb.Append("exhibits, press releases, marketing materials, videos, CDs, DVDs, BBYO websites(both internal and external) and any social media associated with BBYO in any form now existing or that may come to exist in the future.I acknowledge that since my participation in such photographs/video/quotations is voluntary, I will receive no financial compensation and my participation confers upon me no rights of ownership whatsoever to such photographs/video/quotations.I further understand and agree that such photographs/video/quotations may be shared by BBYO with its various partners consistent with these provisions. </p><br/><ul><li style = 'margin: 0; margin-bottom: 15px;' >Acknowledgment and Agreement</li></ul><p style = 'padding-bottom: 15px; margin: 0;' ><strong> I hereby acknowledge that I have fully read, understood and accepted each of the above provisions. I further acknowledge that I have been provided with a copy of the BBYO Code of Conduct.I release BBYO from liability resulting from my participation in programs. </strong></p><br/><p><strong>My signature confirms my understanding of and agreement with these statements and their implications.</strong></p><br/></div>");
sb.Append(string.Format("<div style = 'width: 300px; margin-bottom: 40px;'><p style= 'padding-bottom: 10px; margin: 0;' > Signature of Participant</p><br/><p style = 'padding-bottom: 10px; margin: 0;' > {0} </p><br/><p style= 'padding-bottom: 10px; margin: 0;' > Date: <span>{1}</span></p><br/></div></div></body></html>", "Krishna", "10/10/10"));
sb.Append("</div></body></html>");
string directoryPath = HttpContext.Current.Server.MapPath("~/App_Data/WaiverFormsFiles");
if (!Directory.Exists(directoryPath))
Directory.CreateDirectory(directoryPath);
string path = "~/App_Data/WaiverFormsFiles/" + "TestPage22321.pdf";
StringReader sr = new StringReader(sb.ToString());
Document pdfDoc = new Document(PageSize.A4, 30f, 30f, 30f, 40f);
var writer = PdfWriter.GetInstance(pdfDoc, new FileStream(HttpContext.Current.Server.MapPath(path), FileMode.Create));
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
pdfDoc.Close();
我犯了错误
我的堆栈跟踪在这里更新
at iTextSharp.tool.xml.pipeline.html.HtmlPipeline.Close(IWorkerContext context, Tag t, ProcessObject po)
at iTextSharp.tool.xml.XMLWorker.EndElement(String tag, String ns)
at iTextSharp.tool.xml.parser.XMLParser.EndElement()
at iTextSharp.tool.xml.parser.state.ClosingTagState.Process(Char character)
at iTextSharp.tool.xml.parser.XMLParser.ParseWithReader(TextReader reader)
at iTextSharp.tool.xml.parser.XMLParser.Parse(TextReader reader)
at iTextSharp.tool.xml.XMLWorkerHelper.ParseXHtml(PdfWriter writer, Document doc, TextReader inp)
at WebApplication2_Trial.Pages.pdfTrial2.checkPdf() in E:\VS 2015\WebApplication2 Trial\WebApplication2 Trial\Pages\pdfTrial2.ascx.cs:line 114
&#13;
提前谢谢