locked
Format my label itextsharp RRS feed

  • Question

  • User-611381049 posted

    I'm trying to format my label called (Full Name) here in this code. 

    table.AddCell("Full Name:\r\r" + dr[0].ToString());


    I have searched all over the web where they declare a font and an attribute to link the font to a string where they dynamically added themselves. For example like this

    var normalFont = FontFactory.GetFont(FontFactory.HELVETICA, 12);
    var boldFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12);
    
    var phrase = new Phrase();
    phrase.Add(new Chunk("REASON(S) FOR CANCELLATION:", boldFont));
    phrase.Add(new Chunk(" See Statutoryreason(s) designated by Code No(s) 1 on the reverse side hereof", normalFont));

    However, this time i have added the label under my datareader and trying to format it out without success.

    This is where my btnPDF works

     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);
                table.TotalWidth = 585f;
                table.LockedWidth = true;
    
                var logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/image/logo.jpg"));
                doc1.Add(logo);
    
                var titleFont = FontFactory.GetFont("Arial", 18, Font.BOLD);
                doc1.Add(new Paragraph("Official Report. Member Report ID : " + DDLCase.SelectedValue, titleFont));
    
    
                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();
    
                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("PoliceID :\r\r " + dr[4].ToString());
                    table.AddCell("Police Report Date Time :\r\r " + dr[5].ToString());
                    table.AddCell("Police Report :\r\r " + dr[6].ToString());
                    table.AddCell("Citizen Report :\r\r" + dr[7].ToString());
                    table.AddCell("Admin Official Report :\r\r" + dr[8].ToString());
    
                }
    
                dr.Close();
                doc1.Add(table);
                doc1.Close();
                btnPDF.Enabled = false;
            }
        }


     

    Wednesday, June 5, 2013 10:11 PM

All replies