I am new to asp.net mvc 4.
I have done a simple application using RazorPDF.
Application is to display a normal page in PDF format. I have created a new application and it is running fine .But the same thing when i am implementing in my project it is not working and giving the error as Could not load type 'iTextSharp.text.html.HtmlParser' from assembly 'itextsharp, Version=5.5.3.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca'.
I researched about this and found the concept that why it is displaying this error , as bcoz while installing the RazorPDF it is not installing the HtmlParser inside iTextSharp.
The point I am not getting is if I am doing the same thing in newly application it is installing everything and the code is working fine,if the same i am doing in my project it is not installing all the things through i ma getting this error.
Code is working fine ,no doubt in that.The problem is while installing the RazorPDF in my project it is not installing all the 9 subpackages inside the iTextSharp(HtmlEncoder,HtmlTags,HtmlUtilities,WebColors,HtmlParser,Markup,ITextmyHtmlHandler,HtmlWriter,HtmlTagMap) ,it is installing only 4 subpackages(HtmlEncoder,HtmlTags,HtmlUtilities,WebColors).
As HtmlParser have not installed it is displaying this problem ? Do anyone have knowledge in this (RazorPDF).Can any1 help me out to solve this problem ?
Coding Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using pdf.Models;
namespace pdf.Controllers
{
public class StudentsController : Controller
{
public ActionResult Index()
{
var studentMarks = new List<MarksCard>()
{
new MarksCard(){ RollNo = 101, Subject = "C#",FullMarks = 100, Obtained = 90},
new MarksCard() {RollNo = 101, Subject = "asp.net", FullMarks = 100, Obtained = 80},
new MarksCard() {RollNo = 101, Subject = "MVC", FullMarks = 100,Obtained = 100},
new MarksCard() {RollNo = 101, Subject = "SQL Server", FullMarks = 100, Obtained = 75},
};
return new RazorPDF.PdfResult(studentMarks, "Index");
}
}
}
Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace pdf.Models
{
public class MarksCard
{
public int RollNo
{
get;
set;
}
public string Subject
{
get;
set;
}
public int FullMarks
{
get;
set;
}
public int Obtained { get; set; }
}
}
View
@model IEnumerable<pdf.Models.MarksCard>
@{
Layout = null;
}
<!DOCTYPE html>
<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><tr><td>
@{ var rollNumber = Model.Select(z => z.RollNo).Take(1).ToArray();}
Riyaz Akhter<br />RollNo:@rollNumber[0]</td></tr>
<tr>
<td bgcolor="lightblue">@Html.DisplayNameFor(moel => moel.Subject)</td>
<td bgcolor="lightblue">@Html.DisplayNameFor(model => model.FullMarks)</td>
<td bgcolor="lightblue">@Html.DisplayNameFor(model => model.Obtained)</td></tr>
@{
int total = 0;
}
@foreach (var item in Model)
{
<tr><td>@Html.DisplayFor(modelItem => item.Subject)</td>
<td>@Html.DisplayFor(modelItem => item.FullMarks)</td>
<td>@Html.DisplayFor(modelItem => item.Obtained)</td>
</tr>total += item.Obtained;
}
<tr><td>
</td>
<td>
<strong><font color="GREEN">Total</font></strong>
</td>
<td>@total</td></tr>
</table>
</body>
</html>
Have you read this?:
http://forums.asp.net/t/1925729.aspx?how+to+create+pdf+file+using+razor+pdf
I believe it is what you were looking for.