Stefanescu Gabi
2012-03-05 10:00:46 UTC
Hello, I am using the FreeTextBox control to write the text, which then I want to export to pdf. I am using iText# of course. all works very nicely untill I use the <hr> tag, (the insert rule button). when I want to export to pdf, I get the error.This is the C# code I use: private byte[] RanderHTMLtoPDF(string html)
{
byte[] doc = null; iTextSharp.text.Document idocument = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 32, 32, 50, 50);
using (MemoryStream m = new MemoryStream())
{
iTextSharp.text.pdf.PdfWriter.GetInstance(idocument, m);
idocument.Open(); using (TextReader sReader = new StreamReader(new MemoryStream(System.Text.Encoding.Default.GetBytes(html)), Encoding.Default))
{
iTextSharp.text.html.simpleparser.HTMLWorker worker = new iTextSharp.text.html.simpleparser.HTMLWorker(idocument);
worker.StartDocument();
worker.Parse(sReader);
worker.EndDocument();
}
idocument.Close(); doc = m.ToArray();
}
return doc;
} At the worker.Parse(sReader); it crashes. the error is:ERROR: Object reference not set to an instance of an object. SOURCE: itextsharpSTACK TRACE: at iTextSharp.text.html.simpleparser.HTMLWorker.CreateLineSeparator(IDictionary`2 attrs) at iTextSharp.text.html.simpleparser.HTMLTagProcessors.HTMLTagProcessor_HR.StartElement(HTMLWorker worker, String tag, IDictionary`2 attrs) at iTextSharp.text.html.simpleparser.HTMLWorker.StartElement(String tag, IDictionary`2 attrs) at iTextSharp.text.xml.simpleparser.SimpleXMLParser.ProcessTag(Boolean start) at iTextSharp.text.xml.simpleparser.SimpleXMLParser.Go(TextReader reader) at iTextSharp.text.xml.simpleparser.SimpleXMLParser.Parse(ISimpleXMLDocHandler doc, ISimpleXMLDocHandlerComment comment, TextReader r, Boolean html) at iTextSharp.text.html.simpleparser.HTMLWorker.Parse(TextReader reader) at ExportPDF.RanderHTMLtoPDF(String html) in d:\Lucru\Proiecte\CRMTravel\CRM\App_Code\Framework\PDF\ExportPDF.cs:line 383 at ExportPDF.SaveToPDF(Int32 copyNo, String html) in d:\Lucru\Proiecte\CRMTravel\CRM\App_Code\Framework\PDF\ExportPDF.cs:line 422 at ExportContractPJ..ctor(Int32 id, String title) I really hope you could help me, I took over this from a colegue that left, and I am really stuck. Thanks in advance,Gabriel
{
byte[] doc = null; iTextSharp.text.Document idocument = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 32, 32, 50, 50);
using (MemoryStream m = new MemoryStream())
{
iTextSharp.text.pdf.PdfWriter.GetInstance(idocument, m);
idocument.Open(); using (TextReader sReader = new StreamReader(new MemoryStream(System.Text.Encoding.Default.GetBytes(html)), Encoding.Default))
{
iTextSharp.text.html.simpleparser.HTMLWorker worker = new iTextSharp.text.html.simpleparser.HTMLWorker(idocument);
worker.StartDocument();
worker.Parse(sReader);
worker.EndDocument();
}
idocument.Close(); doc = m.ToArray();
}
return doc;
} At the worker.Parse(sReader); it crashes. the error is:ERROR: Object reference not set to an instance of an object. SOURCE: itextsharpSTACK TRACE: at iTextSharp.text.html.simpleparser.HTMLWorker.CreateLineSeparator(IDictionary`2 attrs) at iTextSharp.text.html.simpleparser.HTMLTagProcessors.HTMLTagProcessor_HR.StartElement(HTMLWorker worker, String tag, IDictionary`2 attrs) at iTextSharp.text.html.simpleparser.HTMLWorker.StartElement(String tag, IDictionary`2 attrs) at iTextSharp.text.xml.simpleparser.SimpleXMLParser.ProcessTag(Boolean start) at iTextSharp.text.xml.simpleparser.SimpleXMLParser.Go(TextReader reader) at iTextSharp.text.xml.simpleparser.SimpleXMLParser.Parse(ISimpleXMLDocHandler doc, ISimpleXMLDocHandlerComment comment, TextReader r, Boolean html) at iTextSharp.text.html.simpleparser.HTMLWorker.Parse(TextReader reader) at ExportPDF.RanderHTMLtoPDF(String html) in d:\Lucru\Proiecte\CRMTravel\CRM\App_Code\Framework\PDF\ExportPDF.cs:line 383 at ExportPDF.SaveToPDF(Int32 copyNo, String html) in d:\Lucru\Proiecte\CRMTravel\CRM\App_Code\Framework\PDF\ExportPDF.cs:line 422 at ExportContractPJ..ctor(Int32 id, String title) I really hope you could help me, I took over this from a colegue that left, and I am really stuck. Thanks in advance,Gabriel