Generate pdf on the fly and email with webmatrix

冷暖自知 提交于 2019-12-11 08:14:05

问题


I have a web application which at the moment generates certificates using a template. Since I original wrote it in php, I used the str_replace built in function to replace values in my template with values from the query.

Now I have changed to asp.net web pages and my aim is to generate certificates in pdf and mail them.

I am using iTextSharp and webmatrix.

Below is part 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 the data from database table. The code above is not working. I am trying to grab the query values and have then in certify1 cell. How can I do this?


回答1:


Try this:

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);
}


来源:https://stackoverflow.com/questions/15202632/generate-pdf-on-the-fly-and-email-with-webmatrix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!