1

我正在尝试将要插入到我的 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 = new Chunk("Full Name", FontFactory.GetFont("dax-black") + table.AddCell(dr[0].ToString()));

更新 最终能够格式化单词 在使用块时返回true iTextSharp

4

0 回答 0