Create PDFs on the fly and email with webmatrix

I have a web application that is currently generating certificates using a template. Since I originally wrote this in php, I used the built-in str_replace function to replace the values ​​in my template with the values ​​from the request.

I have now navigated to asp.net webpages and my goal is to generate pdf certificates and post them.

I am using iTextSharp and webmatrix.

Below is a portion of my code:

 var sql = "SELECT CustomerID, CompanyName, ContactName, Address, City, Country, Phone FROM Customers WHERE CustomerID = 'ALFKI'";
var data = db.Query(sql);

  foreach(var item in data){ var companyname = item.CompanyName;}

PdfPCell certify1 = new PdfPCell(new Phrase("companyname"));
certify1.Colspan = 2;
certify1.Border = 0;
certify1.PaddingTop = 40f;
certify1.HorizontalAlignment = 1;//0=Left, 1=Centre, 2=Right
table.AddCell(certify1);

      

From this code, I am trying to show data from a database table. The above code doesn't work. I am trying to grab the values ​​of the request and then in the certify1 cell. How can i do this?

+1


source to share


1 answer


Try the following:



var sql = "SELECT CustomerID, CompanyName, ContactName, Address, City, Country, Phone FROM Customers WHERE CustomerID = 'ALFKI'";
var data = db.Query(sql);

foreach(var item in data){ 
    var companyname = item.CompanyName;
    PdfPCell certify1 = new PdfPCell(new Phrase(companyname));
    certify1.Colspan = 2;
    certify1.Border = 0;
    certify1.PaddingTop = 40f;
    certify1.HorizontalAlignment = 1;//0=Left, 1=Centre, 2=Right
    table.AddCell(certify1);
}

      

0


source







All Articles