I have a scenario where I need to generate certificate for student based on the course they joined.If a student joins for a single course single certificate is issued,if student joins for a multiple course,single pdf with multiple pages(each page will have individual certificates for each course) needs to be generated.
The below code helps me to generate a pdf for single course.How can I generate pdf for multiple courses. If multiple courses are there then the next page should also use the same template placed at path:
Server.MapPath("~/Template/CertificateTemplate.pdf");
I am using itextsharp library to create documents. Below is the code used to generate pdf.
string formFile = Server.MapPath("~/Template/CertificateTemplate.pdf")
string newFile = Server.MapPath("~/Certificates/" + _dbRegistration.RegistrationNumber + ".pdf");
PdfReader reader = new PdfReader(formFile);
PdfStamper stamper = new PdfStamper(reader, new FileStream(
newFile, FileMode.Create));
var pdfContentBuffer = stamper.GetOverContent(1);
AcroFields fields = stamper.AcroFields;
fields.SetField("ID", _dbRegistration.RegistrationNumber);
fields.SetField("Course", _dbRegistration.Course.FirstOrDefault().Name);
...
stamper.FormFlattening = true;
stamper.Close();
I want to append pdf on the below condition
for(int i=0;i<course.count;i++)
{
AcroFields fields = stamper.AcroFields;
fields.SetField("ID", _dbRegistration.RegistrationNumber);
fields.SetField("Course", _dbRegistration.Course[i].Name);
...
}