Prakash Mondal

Prakash Mondal

  • NA
  • 288
  • 210.1k

How to set Footer using iTaxsharp

Apr 21 2021 11:50 AM
I developed an Inventory System, where a sale invoice is required. So I write a code with itaxsharp. But can't set up a footer in the sale invoice.
 
My code is:
  1. public void downloadInvoice2(string invoice_no)  
  2. {  
  3.     FolderBrowserDialog fbd = new FolderBrowserDialog();  
  4.     if (fbd.ShowDialog() == DialogResult.OK)  
  5.     {  
  6.         try  
  7.         {  
  8.             string PathtobackUp = fbd.SelectedPath.ToString();  
  9.             Document document_indv = new Document(PageSize.A4, 20f, 20f, 10f, 10f);  
  10.             PdfWriter writer = PdfWriter.GetInstance(document_indv, new FileStream(PathtobackUp + "\\12345" + ".pdf", FileMode.Create));  
  11.             //writer.PageEvent = new HeaderFooter();  
  12.             document_indv.Open();  
  13.             string office_bill_type = "Customer Copy";  
  14.             BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);  
  15.             iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 14, iTextSharp.text.Font.BOLD);  
  16.             iTextSharp.text.Font font_14_without_bold = new iTextSharp.text.Font(bf, 14);  
  17.             iTextSharp.text.Font font_14_italic = new iTextSharp.text.Font(bf, 14, iTextSharp.text.Font.BOLDITALIC);  
  18.             iTextSharp.text.Font font_heading = new iTextSharp.text.Font(bf, 24, iTextSharp.text.Font.BOLD);  
  19.             iTextSharp.text.Font font_18 = new iTextSharp.text.Font(bf, 18, iTextSharp.text.Font.BOLD);  
  20.             iTextSharp.text.Font font_14 = new iTextSharp.text.Font(bf, 14, iTextSharp.text.Font.BOLD);  
  21.             iTextSharp.text.Font font_12 = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD);  
  22.             iTextSharp.text.Font font_12_without_bold = new iTextSharp.text.Font(bf, 12);  
  23.             iTextSharp.text.Font font_16 = new iTextSharp.text.Font(bf, 16, iTextSharp.text.Font.BOLD);  
  24.             iTextSharp.text.Font font_16_bold_italic = new iTextSharp.text.Font(bf, 16, iTextSharp.text.Font.BOLDITALIC);  
  25.             iTextSharp.text.Font font_10 = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.BOLD);  
  26.             iTextSharp.text.Font font_8_bold_italic = new iTextSharp.text.Font(bf, 8, iTextSharp.text.Font.BOLDITALIC);  
  27.             iTextSharp.text.Font font_8_bold = new iTextSharp.text.Font(bf, 8, iTextSharp.text.Font.BOLD);  
  28.             //iTextSharp.text.Font font_8_without_bold = new iTextSharp.text.Font(bf, 12);  
  29.             iTextSharp.text.Font font_9_bold_italic = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.BOLDITALIC);  
  30.             iTextSharp.text.Font font_10_bold_italic = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.BOLDITALIC);  
  31.             iTextSharp.text.Font font_10_bold = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.BOLD);  
  32.             iTextSharp.text.Font font_10_without_bold = new iTextSharp.text.Font(bf, 10);  
  33.             iTextSharp.text.Font font_8_without_bold = new iTextSharp.text.Font(bf, 8);  
  34.             iTextSharp.text.Font font_11_bold_italic = new iTextSharp.text.Font(bf, 11, iTextSharp.text.Font.BOLDITALIC);  
  35.             iTextSharp.text.Font font_11 = new iTextSharp.text.Font(bf, 11, iTextSharp.text.Font.BOLD);  
  36.             iTextSharp.text.Font font_12_bold_italic = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLDITALIC);  
  37.             Paragraph new_line = new Paragraph("\n");  
  38.             new_line.SetLeading(0.0f, 0.2f);  
  39.             Paragraph line = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, iTextSharp.text.Color.BLACK, Element.ALIGN_LEFT, 1)));  
  40.             PdfPTable main_table = new PdfPTable(1);  
  41.             main_table.WidthPercentage = 100;  
  42.             //main_table.DefaultCell.FixedHeight = 600f;  
  43.             main_table.SetTotalWidth(new float[] { 30f });  
  44.             PdfPTable marks_table = new PdfPTable(12);  
  45.             marks_table.WidthPercentage = 100;  
  46.             int cell_header_height = 16;  
  47.             //marks_table.DefaultCell.FixedHeight = 500f;  
  48.             marks_table.SetTotalWidth(new float[] { 0.5f, 7f, 1.5f, 0.6f, 1.3f, 1.1f, 1.3f, 1f, 1.3f, 1f, 1.3f, 1.5f });  
  49.             main_table.AddCell(marks_table);  
  50.             ///////// Row  No 1 ////////////  
  51.             PdfPCell cell1 = new PdfPCell(new Phrase(office_bill_type + "                                                                            Tax Invoice" + "\n", font_10_bold_italic));  
  52.             cell1.Colspan = 12;  
  53.             cell1.FixedHeight = 15f;  
  54.             cell1.HorizontalAlignment = Element.ALIGN_LEFT;  
  55.             marks_table.AddCell(cell1);  
  56.             ///////// Row  No 2 ////////////  
  57.             PdfPTable inner_to_table1 = new PdfPTable(1);  
  58.             inner_to_table1.HorizontalAlignment = Element.ALIGN_LEFT;  
  59.             inner_to_table1.SetTotalWidth(new float[] { 10f });  
  60.             inner_to_table1.WidthPercentage = 100;  
  61.             PdfPCell cell2 = new PdfPCell(new Phrase("Shop Name", font_14));  
  62.             cell2.Colspan = 12;  
  63.             cell2.HorizontalAlignment = Element.ALIGN_CENTER;  
  64.             cell2.Border = 0;  
  65.             inner_to_table1.AddCell(cell2);  
  66.             PdfPCell cell22 = new PdfPCell(new Phrase("Shop Address1\n", font_10_without_bold));  
  67.             cell22.Colspan = 12;  
  68.             cell22.HorizontalAlignment = Element.ALIGN_CENTER;  
  69.             cell22.Border = 0;  
  70.             inner_to_table1.AddCell(cell22);  
  71.             PdfPCell nesthousing331 = new PdfPCell(inner_to_table1);  
  72.             nesthousing331.Colspan = 12;  
  73.             nesthousing331.HorizontalAlignment = Element.ALIGN_LEFT;  
  74.             marks_table.AddCell(nesthousing331);  
  75.             ///////// Row  No 3 ////////////  
  76.             PdfPTable inner_to_table = new PdfPTable(1);  
  77.             inner_to_table.HorizontalAlignment = Element.ALIGN_LEFT;  
  78.             inner_to_table.SetTotalWidth(new float[] { 10f });  
  79.             inner_to_table.WidthPercentage = 100;  
  80.             string client_details = "Party Details";  
  81.             inner_to_table.AddCell(getCellNormal(client_details, PdfPCell.ALIGN_LEFT, font_10_without_bold));  
  82.             //"" + client_name + "\n\n" +  
  83.             string details = "Address1\nAddress2";  
  84.             inner_to_table.AddCell(getCellNormal("Mr.Naren Mishra", PdfPCell.ALIGN_LEFT, font_10));  
  85.             inner_to_table.AddCell(getCellNormal(details, PdfPCell.ALIGN_LEFT, font_10_without_bold));  
  86.             PdfPCell nesthousing33 = new PdfPCell(inner_to_table);  
  87.             nesthousing33.Colspan = 6;  
  88.             nesthousing33.HorizontalAlignment = Element.ALIGN_LEFT;  
  89.             marks_table.AddCell(nesthousing33);  
  90.             string invoice_details = "\n\n" +  
  91.             //"Financial Year: " + fin_year +  
  92.             "\nInvoice No:       123456" +  
  93.             "\nInvoice Date:    20-Apr-2021";  
  94.             PdfPCell cell4 = new PdfPCell(new Phrase(invoice_details, font_10_without_bold));  
  95.             cell4.Colspan = 6;  
  96.             cell4.HorizontalAlignment = Element.ALIGN_LEFT;  
  97.             marks_table.AddCell(cell4);  
  98.             ///////// Row  No 4 ////////////  
  99.             PdfPCell cell28 = new PdfPCell(new Phrase("#", font_8_bold_italic));  
  100.             cell28.HorizontalAlignment = Element.ALIGN_LEFT;  
  101.             marks_table.AddCell(cell28);  
  102.             PdfPCell cell29 = new PdfPCell(new Phrase("Description of Goods", font_8_bold_italic));  
  103.             //cell29.Colspan = 3;  
  104.             cell29.HorizontalAlignment = Element.ALIGN_CENTER;  
  105.             marks_table.AddCell(cell29);  
  106.             PdfPCell cell30 = new PdfPCell(new Phrase("HSN/SAC Code", font_8_bold_italic));  
  107.             cell30.HorizontalAlignment = Element.ALIGN_CENTER;  
  108.             marks_table.AddCell(cell30);  
  109.             PdfPCell cell31 = new PdfPCell(new Phrase("Qty", font_8_bold_italic));  
  110.             cell31.HorizontalAlignment = Element.ALIGN_CENTER;  
  111.             marks_table.AddCell(cell31);  
  112.             PdfPCell cell32 = new PdfPCell(new Phrase("Rate", font_8_bold_italic));  
  113.             cell32.HorizontalAlignment = Element.ALIGN_CENTER;  
  114.             marks_table.AddCell(cell32);  
  115.             PdfPCell cell33 = new PdfPCell(new Phrase("Disc. Amount", font_8_bold_italic));  
  116.             cell33.HorizontalAlignment = Element.ALIGN_CENTER;  
  117.             marks_table.AddCell(cell33);  
  118.             PdfPCell cell34 = new PdfPCell(new Phrase("Taxable Amount", font_8_bold_italic));  
  119.             cell34.HorizontalAlignment = Element.ALIGN_CENTER;  
  120.             marks_table.AddCell(cell34);  
  121.             PdfPCell cell35 = new PdfPCell(new Phrase("CGST Rate", font_8_bold_italic));  
  122.             cell35.HorizontalAlignment = Element.ALIGN_CENTER;  
  123.             marks_table.AddCell(cell35);  
  124.             PdfPCell cell36 = new PdfPCell(new Phrase("CGST Amount", font_8_bold_italic));  
  125.             cell36.HorizontalAlignment = Element.ALIGN_CENTER;  
  126.             marks_table.AddCell(cell36);  
  127.             PdfPCell cell37 = new PdfPCell(new Phrase("SGST Rate", font_8_bold_italic));  
  128.             cell37.HorizontalAlignment = Element.ALIGN_CENTER;  
  129.             marks_table.AddCell(cell37);  
  130.             PdfPCell cell38 = new PdfPCell(new Phrase("SGST Amount", font_8_bold_italic));  
  131.             cell38.HorizontalAlignment = Element.ALIGN_CENTER;  
  132.             marks_table.AddCell(cell38);  
  133.             PdfPCell cell39 = new PdfPCell(new Phrase("Amount", font_8_bold_italic));  
  134.             cell39.HorizontalAlignment = Element.ALIGN_CENTER;  
  135.             marks_table.AddCell(cell39);  
  136.             ///////// Row  No 6 ////////////  
  137.             DataTable dt2 = new DataTable();  
  138.             cn.con.Open();  
  139.             cn.cmd.Connection = cn.con;  
  140.             cn.cmd.CommandText = "SELECT A.*,B.ITEM_NAME,B.MODEL_NO,C.COMPANY_NAME,D.CAT_ID,D.CAT_NAME,D.PRINT_NAME,DD.SRLNO,DD.IMEI_NO " +  
  141.                                        "FROM SALE_DETAILS A,PRODUCT_ITEM B, CATEGORY_COMPANY_MAP C, PRODUCT_CATEGORY D, PURCHASE_DETAILS DD " +  
  142.                                        "WHERE A.S_INVOICE_NO_MST_PK = '" + invoice_no + "' AND A.ITEM_PK = B.ITEM_ID " +  
  143.                                        "AND B.CC_MAP_PK = C.CC_MAP_PK AND D.CAT_ID = C.CAT_ID AND A.P_DETAILS_PK = DD.PURCHASE_DETAILS_ID";//SQL  query for getting sale details table  
  144.             cn.da.SelectCommand = cn.cmd;  
  145.             cn.da.Fill(dt2);  
  146.             cn.con.Close();  
  147.             string last_head_id = string.Empty;  
  148.             int slno = 0;  
  149.             if (dt2.Rows.Count > 0)  
  150.             {  
  151.                 for (int k = 0; k < dt2.Rows.Count; k++)  
  152.                 {  
  153.                     slno = k + 1;  
  154.                     PdfPCell cell28D = new PdfPCell(new Phrase(slno.ToString(), font_8_without_bold));  
  155.                     cell28D.HorizontalAlignment = Element.ALIGN_LEFT;  
  156.                     marks_table.AddCell(cell28D);  
  157.                     string desc = "";  
  158.                     desc = "Samsung Galay" + "\n\n" + "Model No: M31" + "\n\n" + "IMEI No: 122324324255"// Retrive from database  
  159.                     PdfPCell cell29D = new PdfPCell(new Phrase(desc, font_8_without_bold));  
  160.                     //cell29.Colspan = 3;  
  161.                     cell29D.HorizontalAlignment = Element.ALIGN_LEFT;  
  162.                     marks_table.AddCell(cell29D);  
  163.                     PdfPCell cell30D = new PdfPCell(new Phrase(dt2.Rows[0]["HSN_SAC"].ToString(), font_8_without_bold));  
  164.                     cell30D.HorizontalAlignment = Element.ALIGN_CENTER;  
  165.                     marks_table.AddCell(cell30D);  
  166.                     PdfPCell cell31D = new PdfPCell(new Phrase(dt2.Rows[0]["QUANTITY"].ToString(), font_8_without_bold));  
  167.                     cell31D.HorizontalAlignment = Element.ALIGN_CENTER;  
  168.                     marks_table.AddCell(cell31D);  
  169.                     PdfPCell cell32D = new PdfPCell(new Phrase(dt2.Rows[0]["RATE"].ToString(), font_8_without_bold));  
  170.                     cell32D.HorizontalAlignment = Element.ALIGN_CENTER;  
  171.                     marks_table.AddCell(cell32D);  
  172.                     PdfPCell cell33D = new PdfPCell(new Phrase(dt2.Rows[0]["DISCOUNT"].ToString(), font_8_without_bold));  
  173.                     cell33D.HorizontalAlignment = Element.ALIGN_CENTER;  
  174.                     marks_table.AddCell(cell33D);  
  175.                     PdfPCell cell34D = new PdfPCell(new Phrase(dt2.Rows[0]["TAXABLE_VALUE"].ToString(), font_8_without_bold));  
  176.                     cell34D.HorizontalAlignment = Element.ALIGN_CENTER;  
  177.                     marks_table.AddCell(cell34D);  
  178.                     PdfPCell cell35D = new PdfPCell(new Phrase(dt2.Rows[0]["CGST_RATE"].ToString() + "%", font_8_without_bold));  
  179.                     cell35D.HorizontalAlignment = Element.ALIGN_CENTER;  
  180.                     marks_table.AddCell(cell35D);  
  181.                     PdfPCell cell36D = new PdfPCell(new Phrase(dt2.Rows[0]["CGST_VALUE"].ToString(), font_8_without_bold));  
  182.                     cell36D.HorizontalAlignment = Element.ALIGN_CENTER;  
  183.                     marks_table.AddCell(cell36D);  
  184.                     PdfPCell cell37D = new PdfPCell(new Phrase(dt2.Rows[0]["SGST_RATE"].ToString() + "%", font_8_without_bold));  
  185.                     cell37D.HorizontalAlignment = Element.ALIGN_CENTER;  
  186.                     marks_table.AddCell(cell37D);  
  187.                     PdfPCell cell38D = new PdfPCell(new Phrase(dt2.Rows[0]["SGST_VALUE"].ToString(), font_8_without_bold));  
  188.                     cell38D.HorizontalAlignment = Element.ALIGN_CENTER;  
  189.                     marks_table.AddCell(cell38D);  
  190.                     PdfPCell cell39D = new PdfPCell(new Phrase(dt2.Rows[0]["NET_VALUE"].ToString(), font_8_without_bold));  
  191.                     cell39D.HorizontalAlignment = Element.ALIGN_CENTER;  
  192.                     marks_table.AddCell(cell39D);  
  193.                 }  
  194.             }  
  195.             double total_inv_amount = 50000.00;  
  196.             PdfPTable inner_rs = new PdfPTable(12);  
  197.             inner_rs.HorizontalAlignment = Element.ALIGN_LEFT;  
  198.             inner_rs.SetTotalWidth(new float[] { 0.5f, 7f, 1.5f, 0.6f, 1.3f, 1.1f, 1.3f, 1f, 1.3f, 1f, 1f, 1.5f });  
  199.             inner_rs.WidthPercentage = 100;  
  200.             Int64 NumVal = Convert.ToInt64(total_inv_amount);  
  201.             string numword = Rupees(NumVal);  
  202.             PdfPCell cell291 = new PdfPCell(new Phrase("[ " + numword + " ]", font_8_bold));  
  203.             cell291.Colspan = 8;  
  204.             cell291.Border = 0;  
  205.             cell291.HorizontalAlignment = Element.ALIGN_LEFT;  
  206.             //marks_table.AddCell(cell29);  
  207.             inner_rs.AddCell(cell291);  
  208.             PdfPCell cell62 = new PdfPCell(new Phrase("Total Amount", font_8_bold));  
  209.             cell62.Colspan = 2;  
  210.             cell62.Border = 0;  
  211.             cell62.FixedHeight = 20f;  
  212.             cell62.HorizontalAlignment = Element.ALIGN_CENTER;  
  213.             inner_rs.AddCell(cell62);  
  214.             PdfPCell cell63 = new PdfPCell(new Phrase("Rs. " + total_inv_amount.ToString("0.00"), font_8_bold));  
  215.             cell63.Colspan = 2;  
  216.             cell63.Border = 0;  
  217.             cell63.FixedHeight = 20f;  
  218.             cell63.HorizontalAlignment = Element.ALIGN_RIGHT;  
  219.             inner_rs.AddCell(cell63);  
  220.             PdfPCell nesthousing333 = new PdfPCell(inner_rs);  
  221.             nesthousing333.Colspan = 12;  
  222.             nesthousing333.HorizontalAlignment = Element.ALIGN_LEFT;  
  223.             marks_table.AddCell(nesthousing333);  
  224.             /////////// Row  No 7 ////////////  
  225.             PdfPCell cell7 = new PdfPCell(new Phrase("", font_10_bold_italic));  
  226.             cell7.HorizontalAlignment = Element.ALIGN_LEFT;  
  227.             cell7.Colspan = 11;  
  228.             cell7.Border = 0;  
  229.             marks_table.AddCell(cell7);  
  230.             PdfPCell cell71 = new PdfPCell(new Phrase("E, O&E", font_10_bold_italic));  
  231.             cell71.Border = 0;  
  232.             cell71.HorizontalAlignment = Element.ALIGN_CENTER;  
  233.             marks_table.AddCell(cell71);  
  234.             ///////// Row  No 8 ////////////  
  235.             PdfPCell cell81 = new PdfPCell(new Phrase("For SD & Associates", font_10_bold_italic));  
  236.             cell81.Border = 0;  
  237.             cell81.Colspan = 12;  
  238.             cell81.HorizontalAlignment = Element.ALIGN_RIGHT;  
  239.             marks_table.AddCell(cell81);  
  240.             ///////// Row  No 9 ////////////  
  241.             PdfPCell cell9 = new PdfPCell(new Phrase("\n\n\n\n\n_________________", font_10_bold_italic));  
  242.             cell9.Border = 0;  
  243.             cell9.Colspan = 12;  
  244.             cell9.HorizontalAlignment = Element.ALIGN_RIGHT;  
  245.             marks_table.AddCell(cell9);  
  246.             ///////// Row  No 10 ////////////  
  247.             PdfPCell cell10 = new PdfPCell(new Phrase("Authorised Signatory", font_10_bold_italic));  
  248.             cell10.Border = 0;  
  249.             cell10.Colspan = 12;  
  250.             cell10.HorizontalAlignment = Element.ALIGN_RIGHT;  
  251.             marks_table.AddCell(cell10);  
  252.             marks_table.AddCell(cell7);  
  253.             document_indv.Add(main_table);  
  254.             document_indv.Close();  
  255.             MessageBox.Show("Successfully Generated ""Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);  
  256.         }  
  257.         catch (Exception pm)  
  258.         {  
  259.             MessageBox.Show("Error:: " + pm.Message, "Alert!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);  
  260.         }  
  261.     }  
  262. }  
pdf copy:
 

Answers (3)