0

I am trying to generate a PDF using HTML template.

i am having trouble in parsing the html generated. here is my code

 using (FileStream fs = new FileStream(System.Web.HttpContext.Current.Server.MapPath("~/Documents/EmailTemplates/test.pdf"), FileMode.Create))
        {
            PdfWriter.GetInstance(document, fs);
            using (StringReader stringReader = new StringReader(contents))
            {
                List<iTextSharp.text.IElement> parsedList = HTMLWorker.ParseToList(stringReader, null);
                document.Open();
                foreach (object item in parsedList)
                {
                    document.Add((IElement)item);
                }
                document.Close();
            }
        }

i get error at HTMLWorker.ParseToList(stringReader, null); shows null reference, but stringReader has content needed

3
  • Where is styles being declared? Commented Feb 2, 2012 at 21:53
  • its part in html template. i see some examples where they gave null fro styles and it is executed perfectly. Commented Feb 2, 2012 at 21:56
  • What version of iTextSharp are you using? In your posted code sample you have HTMLWorker.ParseToList(stringReader, styles) but in your error message you have HTMLWorker.ParseToList(stringReader, null). Which one is your actual code? Also, if you post a stack trace we might be able to help you more. Commented Feb 2, 2012 at 23:03

1 Answer 1

1

Please check the iTextSharp version HTMLWorker.ParseToList() doesnt work properly in latest version, if you are using the latest version, delete it and add new reference to v1.x that will fix your problem

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.