Forums » .NET » ASP.NET »

Unable to cast object of type 'iTextSharp.text.html.simpleparser.TableWrapper' to type 'iT


Posted Date: 03 Dec 2012      Posted By:: Meenakshi     Member Level: Bronze    Member Rank: 2753     Points: 3   Responses: 2



Exception
Unable to cast object of type 'iTextSharp.text.html.simpleparser.TableWrapper' to type 'iTextSharp.text.Meta'


when coding to Convert htmlText to pdfFormat
foreach (IElement element in HTMLWorker.ParseToList(new StringReader(htmlText), null))
{
doc.Add(element); // this point error is throwing

}




Responses

#696620    Author: gandhi      Member Level: Gold      Member Rank: 23     Date: 03/Dec/2012   Rating: 2 out of 52 out of 5     Points: 0

Hi.,

Refer these sites.Hopefully you will get solution.

http://forums.asp.net/t/1510535.aspx/1

http://hspinfo.wordpress.com/2008/01/12/how-to-convert-html-content-to-pdf-file/

http://netpl.blogspot.in/2008/02/unable-to-cast-object-of-type-to-type.html

Regards,
Gandhi


 
#696685    Author: Ravindran      Member Level: Diamond      Member Rank: 3     Date: 04/Dec/2012   Rating: 2 out of 52 out of 5     Points: 4

Hi,

make sure you include namespace using iTextSharp.text.pdf; and using iTextSharp.text.html.simpleparser;

try like this code to convert pdf using itextsharp

using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
using System.IO;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnExportPDF_Click(object sender, EventArgs e)
{
Document pdfDoc = new Document(PageSize.A4, 10, 10, 10, 10);
try
{
PdfWriter.GetInstance(pdfDoc, System.Web.HttpContext.Current.Response.OutputStream);
pdfDoc.Open();
//Assign Html content in a string to write in PDF
string contents = "<h5>EXPORT HTML CONTENT TO PDF</h5><br/><br/><b><u>This content is convert from html string to PDF</u></b><br/><br/><br/><font color='red'>Samples from Ravi!!!</font>";
var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(contents), null);
foreach (var htmlElement in parsedHtmlElements)
pdfDoc.Add(htmlElement as IElement);
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=" + DateTime.Now.ToString("yyyyMMdd") + ".pdf");
System.Web.HttpContext.Current.Response.Write(pdfDoc);
Response.Flush();
Response.End();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}


Regards
N.Ravindran
Your Hard work never fails


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : How to create a windows server for my program?
Previous : I have one dropdown.
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages

Subscribe to Subscribers
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India