Click here to Skip to main content
14,448,449 members
Rate this:
Please Sign up or sign in to vote.
Hi All,

I am trying to generate a pdf from a page . Everthing works fine except the font size. The font size is not changing in Pdf. Could anyone help me please .Any help will be really appreciated .

What I have tried:

private void Generatepdf(string cnscid)
       {
           try
           {
               string tokenno = "";
               string docname = "";
               string room = "";
               SqlDataReader dr = objcon.GetReader("select IN028_01_01.IN028_70,IN013_02,IN028_03,IN013_25 FROM IN028_01_01 INNER JOIN IN028 ON IN028.IN028_01=IN028_01_01.IN028_01 INNER JOIN IN013 ON IN013.IN013_01=IN028.IN013_01  where IN028.IN028_01='" + cnscid + "'");
               if (objcon.dr.Read())
               {
                   tokenno = objcon.dr.GetString(0);
                   docname = objcon.dr.GetString(1);
                   //lbl_datetime.Text = objcon.dr.GetDateTime(2).ToString("dd-MMM-yyyy hh:mm tt");
                   room = objcon.dr.GetString(3);
               }
               objcon.dr.Close();
               string Fortunelogo = Server.MapPath("..//Images//printlogo.png");

               string pdfheader = Server.MapPath("..//Images//printname.png");
               var document = new Document(PageSize.A4, 50, 30, 20, 20);

               var output = new MemoryStream();
               var writer = PdfWriter.GetInstance(document, output);
               document.Open();

               var titleFont = FontFactory.GetFont("Tahoma", 24, Font.BOLDITALIC, new Color(125, 88, 15));

               var itemsTable = @"<table border=0 cellpadding=3 cellspacing=3 >";
               itemsTable += string.Format("<font style=\"font-family:Tahoma;border-collapse:separate;border-spacing: 0 1em;\">");
               itemsTable += string.Format("<tr><td align=\"center\"  style=\"color:#000000;\"><table border=\"0\"><tr><td  align=\"Left\" colspan=\"2\"><img src='" + Fortunelogo + "' height=\"5px\" width=\"5px\" style=border-style: none></td></tr><tr><td colspan=\"20\" align=\"left\" style=\"color:#000000;margin:100px;\"  font-size=\"24px\" Valign=\"middle\">TOKEN</td></tr><tr><td align=\"Left\" colspan=\"20\" style=\"color:#000000;border:solid;\" > Date :" + DateTime.Now.ToString("dd/MMM/yyyy") + " </td></tr><tr><td align=\"Left\" colspan=\"20\" style=\"color:#000000;border:solid;\" >Token No: " + tokenno + "</td></tr><tr><td align=\"Left\" colspan=\"20\" style=\"color:#000000;border:solid;\" >Room No : " + room + "</td></tr><tr><td align=\"Left\" colspan=\"20\" style=\"color:#000000;border:solid;\" >Please be seated .You will be served shortly.</td></tr>");

               itemsTable += string.Format("</table></td></tr></font></table>");
                ArrayList htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(itemsTable), null);
               for (int k = 0; k < htmlarraylist.Count; k++)
               {
                   document.Add((IElement)htmlarraylist[k]);
               }

               document.Close();
               Response.ContentType = "application/pdf";
               Response.AddHeader("Content-Disposition", string.Format("attachment;filename=token.pdf"));
               Response.BinaryWrite(output.ToArray());
           }
           catch (Exception exp)
           {

               Alert.Show(exp.Message.ToString());

           }
       }
Posted
Comments
Gerry Schmitz 21-Dec-19 11:21am
   
I think that looking at the "generated" HTML (or whatever) would be more productive.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100