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
Shovan Saha
NA
321
91.9k
Simple page number for iTextsharp in C#
Jun 13 2017 12:24 PM
Here is my code in C#, visual studio 2015, MS Access 2007 database and iTextsharp report. I need to set simple page number as 1, 2, 3 ...; Please help me.
private void btnPrintForFile_Click(object sender, EventArgs e)
{
//Creating iTextSharp Table from the DataTable data
PdfPTable table = new PdfPTable(12);
PdfPTable pdfTable = new PdfPTable(dataGridView1.ColumnCount);
PdfPTable CountSum = new PdfPTable(1);
pdfTable.HorizontalAlignment = Element.ALIGN_LEFT;
pdfTable.WidthPercentage = 100;
pdfTable.SpacingBefore = 10f;
pdfTable.DefaultCell.BorderWidth = 0;
CountSum.WidthPercentage = 100;
CountSum.SpacingBefore = 10f;
CountSum.DefaultCell.BorderWidth = 0;
iTextSharp.text.Font fontTable = FontFactory.GetFont("Arial", 9, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
iTextSharp.text.Font fontTable1 = FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
//1st Line (Logo + Bank Name + Branch Name)
iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance("JBLWhiteLogo.jpg");
PdfPCell cell1 = new PdfPCell(logo);
cell1.Colspan = 5;
cell1.HorizontalAlignment = Element.ALIGN_RIGHT;
cell1.BorderWidth = 0;
table.AddCell(cell1);
PdfPCell BranchName = new PdfPCell(new Phrase(" Janata Bank Limited" + Environment.NewLine + " Ganna Bazar Branch, Jhenaidah", fontTable1));
BranchName.Colspan = 7;
BranchName.HorizontalAlignment = Element.ALIGN_LEFT;
BranchName.BorderWidth = 0;
table.AddCell(BranchName);
PdfPCell CountAndSum = new PdfPCell(new Phrase("Total Number : " + lblCount.Text.ToString() + Environment.NewLine + "Total Amount : " + lblSum.Text.ToString(), fontTable1));
CountAndSum.HorizontalAlignment = Element.ALIGN_LEFT;
CountAndSum.BorderWidth = 0;
CountSum.AddCell(CountAndSum);
//Adding Header row
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText,fontTable));
pdfTable.AddCell(cell);
}
//Adding DataRow
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
pdfTable.AddCell(new PdfPCell(new Phrase(cell.Value.ToString(), fontTable)) { Border = PdfPCell.BOTTOM_BORDER, Padding = 5, MinimumHeight = 30, PaddingTop = 5 });
}
}
//create a document object
var doc = new Document(PageSize.A4.Rotate());
//get the current directory
string path = Environment.CurrentDirectory;
//get PdfWriter object
PdfWriter.GetInstance(doc, new FileStream(path + "/pdfdoc.pdf", FileMode.Create));
//open the document for writing
doc.Open();
doc.Add(table);
doc.Add(pdfTable);
doc.Add(CountSum);
//close the document
doc.Close();
//view the result pdf file
System.Diagnostics.Process.Start(path + "/pdfdoc.pdf");
}
Reply
Answers (
2
)
Automation of my daily reprot.
On session Timeout My page is not getting refreshed - MVC 4