使用 webmatrix 即时生成 pdf 和电子邮件 [英] Generate pdf on the fly and email with webmatrix
问题描述
我有一个 Web 应用程序,它目前使用模板生成证书.由于我最初是用 php 编写的,因此我使用了 str_replace 内置函数将模板中的值替换为查询中的值.
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.
现在我已更改为asp.net网页,我的目标是生成pdf格式的证书并邮寄.
Now I have changed to asp.net web pages and my aim is to generate certificates in pdf and mail them.
我正在使用 iTextSharp 和 webmatrix.
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);
从这段代码中,我试图显示数据库表中的数据.上面的代码不起作用.我试图获取查询值,然后在 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?
推荐答案
试试这个:
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);
}
这篇关于使用 webmatrix 即时生成 pdf 和电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!