Hello EveryOne,
I am new to MVC, I am doing a Module, where I have a object which contains data, I want that data to be sent to PDF file, basically I want to get the object value into PDF file.
Here is my ActionResult method code :
public ActionResult Print(int id)
{
ListOfPatientsModel _Lst = db.Patients.Find(id);
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
pdfDoc.Add(new Paragraph("Bill Number :" + _Lst.BillNo));
pdfDoc.Add(new Paragraph("Patient Name:" + _Lst.PatientName));
pdfDoc.Add(new Paragraph("MRN Number:" + _Lst.MRN_No));
pdfDoc.Add(new Paragraph("Status:" + _Lst.Status));
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;" +"filename=sample.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
return View();
}
here the Object "_Lst" holds the data which I needed, I want that data to be stored in "pdfDoc" so that I can view it in PDF file.
Note:
->As if now I am able to achieve what i needed, by those 4 lines(bolded), but I want to know is there any other way rather than this.
->"ListOfPatientsModel" is Model Class file.
Regards
Manjuboyz