TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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:
public
void
downloadInvoice2(
string
invoice_no)
{
FolderBrowserDialog fbd =
new
FolderBrowserDialog();
if
(fbd.ShowDialog() == DialogResult.OK)
{
try
{
string
PathtobackUp = fbd.SelectedPath.ToString();
Document document_indv =
new
Document(PageSize.A4, 20f, 20f, 10f, 10f);
PdfWriter writer = PdfWriter.GetInstance(document_indv,
new
FileStream(PathtobackUp +
"\\12345"
+
".pdf"
, FileMode.Create));
//writer.PageEvent = new HeaderFooter();
document_indv.Open();
string
office_bill_type =
"Customer Copy"
;
BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font font =
new
iTextSharp.text.Font(bf, 14, iTextSharp.text.Font.BOLD);
iTextSharp.text.Font font_14_without_bold =
new
iTextSharp.text.Font(bf, 14);
iTextSharp.text.Font font_14_italic =
new
iTextSharp.text.Font(bf, 14, iTextSharp.text.Font.BOLDITALIC);
iTextSharp.text.Font font_heading =
new
iTextSharp.text.Font(bf, 24, iTextSharp.text.Font.BOLD);
iTextSharp.text.Font font_18 =
new
iTextSharp.text.Font(bf, 18, iTextSharp.text.Font.BOLD);
iTextSharp.text.Font font_14 =
new
iTextSharp.text.Font(bf, 14, iTextSharp.text.Font.BOLD);
iTextSharp.text.Font font_12 =
new
iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD);
iTextSharp.text.Font font_12_without_bold =
new
iTextSharp.text.Font(bf, 12);
iTextSharp.text.Font font_16 =
new
iTextSharp.text.Font(bf, 16, iTextSharp.text.Font.BOLD);
iTextSharp.text.Font font_16_bold_italic =
new
iTextSharp.text.Font(bf, 16, iTextSharp.text.Font.BOLDITALIC);
iTextSharp.text.Font font_10 =
new
iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.BOLD);
iTextSharp.text.Font font_8_bold_italic =
new
iTextSharp.text.Font(bf, 8, iTextSharp.text.Font.BOLDITALIC);
iTextSharp.text.Font font_8_bold =
new
iTextSharp.text.Font(bf, 8, iTextSharp.text.Font.BOLD);
//iTextSharp.text.Font font_8_without_bold = new iTextSharp.text.Font(bf, 12);
iTextSharp.text.Font font_9_bold_italic =
new
iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.BOLDITALIC);
iTextSharp.text.Font font_10_bold_italic =
new
iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.BOLDITALIC);
iTextSharp.text.Font font_10_bold =
new
iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.BOLD);
iTextSharp.text.Font font_10_without_bold =
new
iTextSharp.text.Font(bf, 10);
iTextSharp.text.Font font_8_without_bold =
new
iTextSharp.text.Font(bf, 8);
iTextSharp.text.Font font_11_bold_italic =
new
iTextSharp.text.Font(bf, 11, iTextSharp.text.Font.BOLDITALIC);
iTextSharp.text.Font font_11 =
new
iTextSharp.text.Font(bf, 11, iTextSharp.text.Font.BOLD);
iTextSharp.text.Font font_12_bold_italic =
new
iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLDITALIC);
Paragraph new_line =
new
Paragraph(
"\n"
);
new_line.SetLeading(0.0f, 0.2f);
Paragraph line =
new
Paragraph(
new
Chunk(
new
iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, iTextSharp.text.Color.BLACK, Element.ALIGN_LEFT, 1)));
PdfPTable main_table =
new
PdfPTable(1);
main_table.WidthPercentage = 100;
//main_table.DefaultCell.FixedHeight = 600f;
main_table.SetTotalWidth(
new
float
[] { 30f });
PdfPTable marks_table =
new
PdfPTable(12);
marks_table.WidthPercentage = 100;
int
cell_header_height = 16;
//marks_table.DefaultCell.FixedHeight = 500f;
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 });
main_table.AddCell(marks_table);
///////// Row No 1 ////////////
PdfPCell cell1 =
new
PdfPCell(
new
Phrase(office_bill_type +
" Tax Invoice"
+
"\n"
, font_10_bold_italic));
cell1.Colspan = 12;
cell1.FixedHeight = 15f;
cell1.HorizontalAlignment = Element.ALIGN_LEFT;
marks_table.AddCell(cell1);
///////// Row No 2 ////////////
PdfPTable inner_to_table1 =
new
PdfPTable(1);
inner_to_table1.HorizontalAlignment = Element.ALIGN_LEFT;
inner_to_table1.SetTotalWidth(
new
float
[] { 10f });
inner_to_table1.WidthPercentage = 100;
PdfPCell cell2 =
new
PdfPCell(
new
Phrase(
"Shop Name"
, font_14));
cell2.Colspan = 12;
cell2.HorizontalAlignment = Element.ALIGN_CENTER;
cell2.Border = 0;
inner_to_table1.AddCell(cell2);
PdfPCell cell22 =
new
PdfPCell(
new
Phrase(
"Shop Address1\n"
, font_10_without_bold));
cell22.Colspan = 12;
cell22.HorizontalAlignment = Element.ALIGN_CENTER;
cell22.Border = 0;
inner_to_table1.AddCell(cell22);
PdfPCell nesthousing331 =
new
PdfPCell(inner_to_table1);
nesthousing331.Colspan = 12;
nesthousing331.HorizontalAlignment = Element.ALIGN_LEFT;
marks_table.AddCell(nesthousing331);
///////// Row No 3 ////////////
PdfPTable inner_to_table =
new
PdfPTable(1);
inner_to_table.HorizontalAlignment = Element.ALIGN_LEFT;
inner_to_table.SetTotalWidth(
new
float
[] { 10f });
inner_to_table.WidthPercentage = 100;
string
client_details =
"Party Details"
;
inner_to_table.AddCell(getCellNormal(client_details, PdfPCell.ALIGN_LEFT, font_10_without_bold));
//"" + client_name + "\n\n" +
string
details =
"Address1\nAddress2"
;
inner_to_table.AddCell(getCellNormal(
"Mr.Naren Mishra"
, PdfPCell.ALIGN_LEFT, font_10));
inner_to_table.AddCell(getCellNormal(details, PdfPCell.ALIGN_LEFT, font_10_without_bold));
PdfPCell nesthousing33 =
new
PdfPCell(inner_to_table);
nesthousing33.Colspan = 6;
nesthousing33.HorizontalAlignment = Element.ALIGN_LEFT;
marks_table.AddCell(nesthousing33);
string
invoice_details =
"\n\n"
+
//"Financial Year: " + fin_year +
"\nInvoice No: 123456"
+
"\nInvoice Date: 20-Apr-2021"
;
PdfPCell cell4 =
new
PdfPCell(
new
Phrase(invoice_details, font_10_without_bold));
cell4.Colspan = 6;
cell4.HorizontalAlignment = Element.ALIGN_LEFT;
marks_table.AddCell(cell4);
///////// Row No 4 ////////////
PdfPCell cell28 =
new
PdfPCell(
new
Phrase(
"#"
, font_8_bold_italic));
cell28.HorizontalAlignment = Element.ALIGN_LEFT;
marks_table.AddCell(cell28);
PdfPCell cell29 =
new
PdfPCell(
new
Phrase(
"Description of Goods"
, font_8_bold_italic));
//cell29.Colspan = 3;
cell29.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell29);
PdfPCell cell30 =
new
PdfPCell(
new
Phrase(
"HSN/SAC Code"
, font_8_bold_italic));
cell30.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell30);
PdfPCell cell31 =
new
PdfPCell(
new
Phrase(
"Qty"
, font_8_bold_italic));
cell31.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell31);
PdfPCell cell32 =
new
PdfPCell(
new
Phrase(
"Rate"
, font_8_bold_italic));
cell32.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell32);
PdfPCell cell33 =
new
PdfPCell(
new
Phrase(
"Disc. Amount"
, font_8_bold_italic));
cell33.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell33);
PdfPCell cell34 =
new
PdfPCell(
new
Phrase(
"Taxable Amount"
, font_8_bold_italic));
cell34.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell34);
PdfPCell cell35 =
new
PdfPCell(
new
Phrase(
"CGST Rate"
, font_8_bold_italic));
cell35.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell35);
PdfPCell cell36 =
new
PdfPCell(
new
Phrase(
"CGST Amount"
, font_8_bold_italic));
cell36.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell36);
PdfPCell cell37 =
new
PdfPCell(
new
Phrase(
"SGST Rate"
, font_8_bold_italic));
cell37.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell37);
PdfPCell cell38 =
new
PdfPCell(
new
Phrase(
"SGST Amount"
, font_8_bold_italic));
cell38.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell38);
PdfPCell cell39 =
new
PdfPCell(
new
Phrase(
"Amount"
, font_8_bold_italic));
cell39.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell39);
///////// Row No 6 ////////////
DataTable dt2 =
new
DataTable();
cn.con.Open();
cn.cmd.Connection = cn.con;
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 "
+
"FROM SALE_DETAILS A,PRODUCT_ITEM B, CATEGORY_COMPANY_MAP C, PRODUCT_CATEGORY D, PURCHASE_DETAILS DD "
+
"WHERE A.S_INVOICE_NO_MST_PK = '"
+ invoice_no +
"' AND A.ITEM_PK = B.ITEM_ID "
+
"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
cn.da.SelectCommand = cn.cmd;
cn.da.Fill(dt2);
cn.con.Close();
string
last_head_id =
string
.Empty;
int
slno = 0;
if
(dt2.Rows.Count > 0)
{
for
(
int
k = 0; k < dt2.Rows.Count; k++)
{
slno = k + 1;
PdfPCell cell28D =
new
PdfPCell(
new
Phrase(slno.ToString(), font_8_without_bold));
cell28D.HorizontalAlignment = Element.ALIGN_LEFT;
marks_table.AddCell(cell28D);
string
desc =
""
;
desc =
"Samsung Galay"
+
"\n\n"
+
"Model No: M31"
+
"\n\n"
+
"IMEI No: 122324324255"
;
// Retrive from database
PdfPCell cell29D =
new
PdfPCell(
new
Phrase(desc, font_8_without_bold));
//cell29.Colspan = 3;
cell29D.HorizontalAlignment = Element.ALIGN_LEFT;
marks_table.AddCell(cell29D);
PdfPCell cell30D =
new
PdfPCell(
new
Phrase(dt2.Rows[0][
"HSN_SAC"
].ToString(), font_8_without_bold));
cell30D.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell30D);
PdfPCell cell31D =
new
PdfPCell(
new
Phrase(dt2.Rows[0][
"QUANTITY"
].ToString(), font_8_without_bold));
cell31D.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell31D);
PdfPCell cell32D =
new
PdfPCell(
new
Phrase(dt2.Rows[0][
"RATE"
].ToString(), font_8_without_bold));
cell32D.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell32D);
PdfPCell cell33D =
new
PdfPCell(
new
Phrase(dt2.Rows[0][
"DISCOUNT"
].ToString(), font_8_without_bold));
cell33D.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell33D);
PdfPCell cell34D =
new
PdfPCell(
new
Phrase(dt2.Rows[0][
"TAXABLE_VALUE"
].ToString(), font_8_without_bold));
cell34D.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell34D);
PdfPCell cell35D =
new
PdfPCell(
new
Phrase(dt2.Rows[0][
"CGST_RATE"
].ToString() +
"%"
, font_8_without_bold));
cell35D.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell35D);
PdfPCell cell36D =
new
PdfPCell(
new
Phrase(dt2.Rows[0][
"CGST_VALUE"
].ToString(), font_8_without_bold));
cell36D.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell36D);
PdfPCell cell37D =
new
PdfPCell(
new
Phrase(dt2.Rows[0][
"SGST_RATE"
].ToString() +
"%"
, font_8_without_bold));
cell37D.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell37D);
PdfPCell cell38D =
new
PdfPCell(
new
Phrase(dt2.Rows[0][
"SGST_VALUE"
].ToString(), font_8_without_bold));
cell38D.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell38D);
PdfPCell cell39D =
new
PdfPCell(
new
Phrase(dt2.Rows[0][
"NET_VALUE"
].ToString(), font_8_without_bold));
cell39D.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell39D);
}
}
double
total_inv_amount = 50000.00;
PdfPTable inner_rs =
new
PdfPTable(12);
inner_rs.HorizontalAlignment = Element.ALIGN_LEFT;
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 });
inner_rs.WidthPercentage = 100;
Int64 NumVal = Convert.ToInt64(total_inv_amount);
string
numword = Rupees(NumVal);
PdfPCell cell291 =
new
PdfPCell(
new
Phrase(
"[ "
+ numword +
" ]"
, font_8_bold));
cell291.Colspan = 8;
cell291.Border = 0;
cell291.HorizontalAlignment = Element.ALIGN_LEFT;
//marks_table.AddCell(cell29);
inner_rs.AddCell(cell291);
PdfPCell cell62 =
new
PdfPCell(
new
Phrase(
"Total Amount"
, font_8_bold));
cell62.Colspan = 2;
cell62.Border = 0;
cell62.FixedHeight = 20f;
cell62.HorizontalAlignment = Element.ALIGN_CENTER;
inner_rs.AddCell(cell62);
PdfPCell cell63 =
new
PdfPCell(
new
Phrase(
"Rs. "
+ total_inv_amount.ToString(
"0.00"
), font_8_bold));
cell63.Colspan = 2;
cell63.Border = 0;
cell63.FixedHeight = 20f;
cell63.HorizontalAlignment = Element.ALIGN_RIGHT;
inner_rs.AddCell(cell63);
PdfPCell nesthousing333 =
new
PdfPCell(inner_rs);
nesthousing333.Colspan = 12;
nesthousing333.HorizontalAlignment = Element.ALIGN_LEFT;
marks_table.AddCell(nesthousing333);
/////////// Row No 7 ////////////
PdfPCell cell7 =
new
PdfPCell(
new
Phrase(
""
, font_10_bold_italic));
cell7.HorizontalAlignment = Element.ALIGN_LEFT;
cell7.Colspan = 11;
cell7.Border = 0;
marks_table.AddCell(cell7);
PdfPCell cell71 =
new
PdfPCell(
new
Phrase(
"E, O&E"
, font_10_bold_italic));
cell71.Border = 0;
cell71.HorizontalAlignment = Element.ALIGN_CENTER;
marks_table.AddCell(cell71);
///////// Row No 8 ////////////
PdfPCell cell81 =
new
PdfPCell(
new
Phrase(
"For SD & Associates"
, font_10_bold_italic));
cell81.Border = 0;
cell81.Colspan = 12;
cell81.HorizontalAlignment = Element.ALIGN_RIGHT;
marks_table.AddCell(cell81);
///////// Row No 9 ////////////
PdfPCell cell9 =
new
PdfPCell(
new
Phrase(
"\n\n\n\n\n_________________"
, font_10_bold_italic));
cell9.Border = 0;
cell9.Colspan = 12;
cell9.HorizontalAlignment = Element.ALIGN_RIGHT;
marks_table.AddCell(cell9);
///////// Row No 10 ////////////
PdfPCell cell10 =
new
PdfPCell(
new
Phrase(
"Authorised Signatory"
, font_10_bold_italic));
cell10.Border = 0;
cell10.Colspan = 12;
cell10.HorizontalAlignment = Element.ALIGN_RIGHT;
marks_table.AddCell(cell10);
marks_table.AddCell(cell7);
document_indv.Add(main_table);
document_indv.Close();
MessageBox.Show(
"Successfully Generated "
,
"Success!"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
(Exception pm)
{
MessageBox.Show(
"Error:: "
+ pm.Message,
"Alert!"
, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
pdf copy:
Reply
Answers (
3
)
Move next previous record on label in c#
Packet received out-of-order. Expected 1; got 2.'