I'm using mvc4
,here I'm using razorpdf
to convert my view to pdf, but I'm getting an error - Unable to cast object of type iTextSharp.text.Paragraph to type iTextSharp.text.Table
.
This is the sample code I'm using:
@{
Layout = "~/Views/Shared/_PdfLayout.cshtml";
}
<html>
<body>
<table border="1" width='500' bordercolor="RED"><tr><td colspan="3" bgcolor="LightGreen" align="center" valign="top">SSLC Marks Sheet 2013</td></tr></table></body>
</html>
Since your code is using the
_PdfLayout.chtml
the code needs to be written using iTextSharp in an xml format and not html. remove the body tags, change the<tr>
to<row>
, change the<td>
to<cell>
and then use<chunk>
your text here</chunk>
to hold the text inside each cell. Here is an example: