我正在尝试将我要插入到我的pdf文件中的某些单词加粗。单词可以在我的table.addcell(“words”)之后找到。我把它加粗,以便在数据和标签之间进行识别。
protected void btnPDF_Click(object sender, EventArgs e)
{
var doc1 = new Document();
var filename = "MyTestPDF" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".pdf";
var output = new FileStream(Path.Combine("C:\\Users\\apr12mpsip\\Desktop\\New folder", filename), FileMode.Create);
PdfWriter.GetInstance(doc1, output);
doc1.Open();
PdfPTable table = new PdfPTable(2);
////actual width of table in points
table.TotalWidth = 585f;
////fix the absolute width of the table
table.LockedWidth = true;
SqlConnection con = new SqlConnection("Data Source = localhost; Initial Catalog = project; Integrated Security = SSPI");
SqlCommand cm = new SqlCommand("Select lro.fullname, lro.contact, mr.typeofcrime, mr.location,mr.crdatetime, pr.policeid, pr.prdatetime, pr.policereport, mr.citizenreport, aor.officialreport from MemberReport mr, PoliceReport pr, LoginRegisterOthers lro, AdminOfficialReport aor where mr.memberreportid = '" + DDLCase.SelectedValue + "' and mr.memberreportid=pr.memberreportid and pr.policereportid=aor.policereportid", con);
con.Open();
SqlDataReader dr;
dr = cm.ExecuteReader();
PdfPCell header = new PdfPCell(new Phrase("OFFICIAL REPORT "));
if (dr.Read())
{
table.AddCell("Full Name :\r\r "+ dr[0].ToString());
table.AddCell("Contact :\r\r "+ dr[1].ToString());
table.AddCell("Type Of Crime :\r\r "+ dr[2].ToString());
table.AddCell("Location :\r\r "+ dr[3].ToString());
table.AddCell("Citizen Report Date Time :\r\r "+ dr[4].ToString());
table.AddCell("PoliceID :\r\r "+ dr[5].ToString());
table.AddCell("Police Report Date Time :\r\r "+ dr[6].ToString());
table.AddCell("Police Report :\r\r "+ dr[7].ToString());
table.AddCell("Citizen Report :\r\r"+ dr[8].ToString());
table.AddCell("Admin Official Report :\r\r"+ dr[9].ToString());
}
dr.Close();
doc1.Add(table);
doc1.Close();
}
我尝试使用chunk,它似乎也没有用。
Chunk chunk = new Chunk("Full Name", FontFactory.GetFont("dax-black") + table.AddCell(dr[0].ToString()));
更新 最后能够格式化这个词 Return true when chunk is used iTextSharp