Discussion:
[iText-questions] HR tag error - Object reference not set to an instance of an object.
Stefanescu Gabi
2012-03-05 10:00:46 UTC
Permalink
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
iText Info
2012-03-05 10:07:00 UTC
Permalink
Op 5/03/2012 11:00, Stefanescu Gabi schreef:
> iTextSharp.text.html.simpleparser.HTMLWorker worker
HTMLWorker is no longer supported.
It's discontinued in favor of XML Worker:
http://demo.itextsupport.com/xmlworker
Stefanescu Gabi
2012-03-05 12:36:13 UTC
Permalink
Ok, thanks, I have found it, but only for java (the .jar files). is it available for c# too? Thank you Gabriel
Date: Mon, 5 Mar 2012 11:07:00 +0100
From: ***@1t3xt.info
To: itext-***@lists.sourceforge.net
Subject: Re: [iText-questions] HR tag error - Object reference not set to an instance of an object.








Op 5/03/2012 11:00, Stefanescu Gabi schreef:
iTextSharp.text.html.simpleparser.HTMLWorker
worker
HTMLWorker is no longer supported.

It's discontinued in favor of XML Worker:
http://demo.itextsupport.com/xmlworker




------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
iText Info
2012-03-05 12:40:59 UTC
Permalink
Op 5/03/2012 13:36, Stefanescu Gabi schreef:
> Ok, thanks, I have found it, but only for java (the .jar files). is it
> available for c# too?
Yes, http://sourceforge.net/projects/itextsharp/files/xmlworker/
We're working on the 1.1.2 release. It's much better than 1.1.1.
Stefanescu Gabi
2012-03-05 12:44:14 UTC
Permalink
thanks for your fast and helpful replys.
> Date: Mon, 5 Mar 2012 13:40:59 +0100
> From: ***@1t3xt.info
> To: itext-***@lists.sourceforge.net
> Subject: Re: [iText-questions] HR tag error - Object reference not set to an instance of an object.
>
> Op 5/03/2012 13:36, Stefanescu Gabi schreef:
> > Ok, thanks, I have found it, but only for java (the .jar files). is it
> > available for c# too?
> Yes, http://sourceforge.net/projects/itextsharp/files/xmlworker/
> We're working on the 1.1.2 release. It's much better than 1.1.1.
>
> ------------------------------------------------------------------------------
> Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-dev2
> _______________________________________________
> iText-questions mailing list
> iText-***@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> iText(R) is a registered trademark of 1T3XT BVBA.
> Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
> Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
Stefanescu Gabi
2012-03-05 13:30:09 UTC
Permalink
Could you please guide me to a link where there is an implementation example in C# that could help me write with XMLWorker what I wrote here with HMTL worker? 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;
}

I can't make the transition to XMLWorker and I am a bit pressed by time Thanks,Gabriel > Date: Mon, 5 Mar 2012 13:40:59 +0100
> From: ***@1t3xt.info
> To: itext-***@lists.sourceforge.net
> Subject: Re: [iText-questions] HR tag error - Object reference not set to an instance of an object.
>
> Op 5/03/2012 13:36, Stefanescu Gabi schreef:
> > Ok, thanks, I have found it, but only for java (the .jar files). is it
> > available for c# too?
> Yes, http://sourceforge.net/projects/itextsharp/files/xmlworker/
> We're working on the 1.1.2 release. It's much better than 1.1.1.
>
> ------------------------------------------------------------------------------
> Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-dev2
> _______________________________________________
> iText-questions mailing list
> iText-***@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> iText(R) is a registered trademark of 1T3XT BVBA.
> Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
> Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
Loading...