<pre lang="c#"><pre lang="c#"><pre lang="c#"><pre lang="c#">
You try to pdf table concept using this type of code
public string AssessmentInfopdfTwo(EntityStudentAssessment oStudentAssmInfo)
{
var FontColour = new BaseColor(181, 171, 134);
var innerColour = new BaseColor(204, 197, 166);
var tblwidth = 550f;
FontFactory.RegisterDirectories();
Font Defaultfont = new Font(FontFactory.GetFont("helvetica", 9, Font.NORMAL));
Font MainHeading = new Font(FontFactory.GetFont("helvetica", 16, Font.BOLD));
Font SubHeading = new Font(FontFactory.GetFont("helvetica", 14, Font.NORMAL));
Font DateHeading = new Font(FontFactory.GetFont("helvetica", 12, Font.NORMAL));
Font ExamDateHeading = new Font(FontFactory.GetFont("helvetica", 14, Font.NORMAL));
Font PageHeading = new Font(FontFactory.GetFont("helvetica", 16, Font.BOLD));
Font TableHeading = new Font(FontFactory.GetFont("helvetica", 9, Font.BOLD));
Font TableContent = new Font(FontFactory.GetFont("helvetica", 9, Font.NORMAL));
Font TableQualitativeContent = new Font(FontFactory.GetFont("helvetica", 8, Font.ITALIC));
iTextSharp.text.Font Default = Defaultfont;
string PdfName = "schloud" + DateTime.Now.Ticks + ".pdf";
Document doc = new Document(iTextSharp.text.PageSize.A4, 5, 5, 50, 25);
string pdfFilePath = Server.MapPath("\\Temp\\");
PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(pdfFilePath + PdfName, FileMode.Create));
doc.Open();
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(Server.MapPath("../../Img/logo/ReportLogo.png"));
iTextSharp.text.Image footerlogo = iTextSharp.text.Image.GetInstance(Server.MapPath("../../Img/logo/footerlogo.png"));
float[] FirstPage = new float[2];
FirstPage[0] = 65f;
FirstPage[1] = 265f;
PdfPTable dammy = new PdfPTable(1);
PdfPCell Dummycell = new PdfPCell(new Phrase(" ", Defaultfont));
Dummycell.BorderWidth = 0;
dammy.AddCell(Dummycell);
doc.Add(dammy);
PdfPTable schooldetails = new PdfPTable(2);
schooldetails.TotalWidth = 550f;
schooldetails.LockedWidth = true;
schooldetails.DefaultCell.BackgroundColor = FontColour;
schooldetails.SetWidths(FirstPage);
jpg.ScaleAbsolute(65f, 85f);
PdfPCell Schoollogo = new PdfPCell(jpg);
Schoollogo.Left = 0;
Schoollogo.PaddingLeft = 0;
Schoollogo.BorderWidth = 0;
Schoollogo.BackgroundColor = FontColour;
Schoollogo.HorizontalAlignment = Element.ALIGN_LEFT;
schooldetails.AddCell(Schoollogo);
PdfPTable schoolNameDetails = new PdfPTable(1);
schoolNameDetails.TotalWidth = 550f;
schoolNameDetails.DefaultCell.BackgroundColor = FontColour;
PdfPCell SchoolName = new PdfPCell(new Phrase(" International", MainHeading));
SchoolName.BorderWidth = 0;
SchoolName.PaddingTop = 5f;
SchoolName.PaddingBottom = 5f;
SchoolName.PaddingLeft= 0;
schoolNameDetails.AddCell(SchoolName);
PdfPCell SchoolCenter = new PdfPCell(new Phrase(" CENTRE NO: 10721", ExamDateHeading));
SchoolCenter.BorderWidth = 0;
SchoolCenter.PaddingTop = 10f;
SchoolCenter.PaddingBottom = 5f;
SchoolCenter.PaddingLeft = 5f;
schoolNameDetails.AddCell(SchoolCenter);
PdfPCell SchoolTable = new PdfPCell(schoolNameDetails);
SchoolTable.BorderWidth = 0;
SchoolTable.BackgroundColor = FontColour;
schooldetails.AddCell(SchoolTable);
doc.Add(schooldetails);
float[] SubjecttableWidths = new float[4];
SubjecttableWidths[0] = 80f;
SubjecttableWidths[1] = 80f;
SubjecttableWidths[2] = 40f;
SubjecttableWidths[3] = 40f;
PdfPTable SubjectTableRight = new PdfPTable(4);
SubjectTableRight.TotalWidth = 260f;
SubjectTableRight.LockedWidth = true;
SubjectTableRight.SetWidths(SubjecttableWidths);
PdfPCell Subject = new PdfPCell(new Phrase("SUBJECTS", TableHeading)) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE };
Subject.Padding = 10f;
Subject.BackgroundColor = FontColour;
SubjectTableRight.AddCell(Subject);
PdfPCell Personnal = new PdfPCell(new Phrase("FACILITATOR", TableHeading)) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, BackgroundColor = FontColour };
SubjectTableRight.AddCell(Personnal);
PdfPCell Mark = new PdfPCell(new Phrase("%MARK", TableHeading)) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, BackgroundColor = FontColour };
SubjectTableRight.AddCell(Mark);
PdfPCell Grade = new PdfPCell(new Phrase("GRADE", TableHeading)) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, BackgroundColor = FontColour };
SubjectTableRight.AddCell(Grade);
SubjectTableRight.SpacingBefore = 10;
PdfPTable SubjectTableLeft = new PdfPTable(4);
SubjectTableLeft.TotalWidth = 260f;
SubjectTableLeft.LockedWidth = true;
SubjectTableLeft.SetWidths(SubjecttableWidths);
PdfPCell Subject1 = new PdfPCell(new Phrase("SUBJECTS", TableHeading)) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE };
Subject1.Padding = 10f;
Subject1.BackgroundColor = FontColour;
SubjectTableLeft.AddCell(Subject1);
PdfPCell Personnal1 = new PdfPCell(new Phrase("FACILITATOR", TableHeading)) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, BackgroundColor = FontColour };
SubjectTableLeft.AddCell(Personnal1);
PdfPCell Mark1 = new PdfPCell(new Phrase("%MARK", TableHeading)) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, BackgroundColor = FontColour };
SubjectTableLeft.AddCell(Mark1);
PdfPCell Grade1 = new PdfPCell(new Phrase("GRADE", TableHeading)) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, BackgroundColor = FontColour };
SubjectTableLeft.AddCell(Grade1);
SubjectTableLeft.SpacingBefore = 10;
<pre>
if (oStudentAssmInfo.oExamList.Count() > 0)
{
int i = 0;
foreach (EntitySubject oProj in oStudentAssmInfo.oSubjectList)
{
i++;
int index = oStudentAssmInfo.oExamList.FindIndex(f => f.oSubject.SubjectId == oProj.SubjectId);
if (index >= 0)
{
EntityExam oExam = oStudentAssmInfo.oExamList.Where(c => c.oSubject.SubjectId == oProj.SubjectId).First();
PdfPCell Subjects = new PdfPCell();
Subjects = new PdfPCell(new Phrase(oExam.oSubject.SubjectName, TableHeading));
Subjects.BackgroundColor = FontColour;
Subjects.VerticalAlignment = Element.ALIGN_MIDDLE;
Subjects.Padding = 10f;
PdfPCell persannals = new PdfPCell();
persannals = new PdfPCell(new Phrase(oExam.oStaff.FullName, Defaultfont));
persannals.VerticalAlignment = Element.ALIGN_MIDDLE;
PdfPCell Marks = new PdfPCell();
if (oExam.TotalMark != "-1")
{
Marks = new PdfPCell(new Phrase(oExam.TotalMark, Defaultfont));
}
else
{
Marks = new PdfPCell(new Phrase("absent", Defaultfont));
}
Marks.VerticalAlignment = Element.ALIGN_MIDDLE;
Marks.HorizontalAlignment = Element.ALIGN_CENTER;
PdfPCell Grades = new PdfPCell();
Grades = new PdfPCell(new Phrase(oExam.Grade, Defaultfont));
Grades.HorizontalAlignment = Element.ALIGN_CENTER;
Grades.VerticalAlignment = Element.ALIGN_MIDDLE;
PdfPCell Remarks = new PdfPCell();
Remarks = new PdfPCell(new Phrase(oExam.Remarks, Defaultfont));
Remarks.ExtraParagraphSpace = 5f;
Remarks.VerticalAlignment = Element.ALIGN_MIDDLE;
if (i % 2 == 0)
{
SubjectTableRight.AddCell(Subjects);
SubjectTableRight.AddCell(persannals);
SubjectTableRight.AddCell(Marks);
SubjectTableRight.AddCell(Grades);
}
else
{
SubjectTableLeft.AddCell(Subjects);
SubjectTableLeft.AddCell(persannals);
SubjectTableLeft.AddCell(Marks);
SubjectTableLeft.AddCell(Grades);
}
}
else
{
PdfPCell Subjects = new PdfPCell();
Subjects = new PdfPCell(new Phrase(oProj.SubjectName, TableHeading));
Subjects.BackgroundColor = FontColour;
Subjects.VerticalAlignment = Element.ALIGN_MIDDLE;
Subjects.Padding = 10f;
if (i % 2 == 0)
{
SubjectTableRight.AddCell(Subjects);
SubjectTableRight.AddCell(new PdfPCell(new Phrase(" ", Defaultfont)) { Padding = 3f, BackgroundColor = innerColour });
SubjectTableRight.AddCell(new PdfPCell(new Phrase(" ", Defaultfont)) { Padding = 3f, BackgroundColor = innerColour });
SubjectTableRight.AddCell(new PdfPCell(new Phrase(" ", Defaultfont)) { Padding = 3f, BackgroundColor = innerColour });
}
else
{
SubjectTableLeft.AddCell(Subjects);
SubjectTableLeft.AddCell(new PdfPCell(new Phrase(" ", Defaultfont)) { Padding = 3f, BackgroundColor = innerColour });
SubjectTableLeft.AddCell(new PdfPCell(new Phrase(" ", Defaultfont)) { Padding = 3f, BackgroundColor = innerColour });
SubjectTableLeft.AddCell(new PdfPCell(new Phrase(" ", Defaultfont)) { Padding = 3f, BackgroundColor = innerColour });
}
}
}
}
else
{
SubjectTableRight.AddCell(" ");
SubjectTableRight.AddCell("");
SubjectTableRight.AddCell("");
SubjectTableRight.AddCell("");
SubjectTableLeft.AddCell(" ");
SubjectTableLeft.AddCell("");
SubjectTableLeft.AddCell("");
SubjectTableLeft.AddCell("");
}
PdfPTable SubjectTableParent = new PdfPTable(2);
SubjectTableParent.TotalWidth = 560f;
SubjectTableParent.LockedWidth = true;
SubjectTableParent.DefaultCell.Border = 0;
SubjectTableParent.SpacingBefore = 10;
SubjectTableParent.AddCell(SubjectTableRight);
SubjectTableParent.AddCell(SubjectTableLeft);
SubjectTableParent.SpacingAfter = 18;
doc.Add(SubjectTableParent);
doc.Close();
return PdfName;
}
public ActionResult PrintAssessment()
{
EntityStudentAssessment oStudentAssmInfo = new BSNSTest().GetStudentWiseResult(Request.QueryString["StudentId"].ToString(), Request.QueryString["TestId"].ToString(), Request.QueryString["BatchId"].ToString());
string file = "";
file = AssessmentInfopdfTwo(oStudentAssmInfo);
var fileStream = new FileStream(Server.MapPath("\\Temp\\" + file),
FileMode.Open,
FileAccess.Read
);
var fsResult = new FileStreamResult(fileStream, "application/pdf");
return fsResult;
}<pre lang="c#"><pre lang="c#">