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
priya santhi
NA
33
14.4k
how to add header and footer for pdf using c#.net
Nov 26 2014 7:36 AM
hii...
i am very tried to create header and footer for pdf using c#...here am using itextsharp for converting gridview(details) to pdf file...plz anyone help me..urgent
private void button1_Click(object sender, EventArgs e)
{
PdfPTable pdfTable = new PdfPTable(dataGridView1.ColumnCount);
pdfTable.DefaultCell.Padding = 3;
pdfTable.WidthPercentage = 30;
pdfTable.HorizontalAlignment = Element.ALIGN_LEFT;
pdfTable.DefaultCell.BorderWidth = 1;
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
//try
//{
// PdfPCell cell = new PdfPCell(new Phrase("Header spanning 3 columns"));
// cell.BackgroundColor = new BaseColor(System.Drawing.Color.Red);
// cell.BackgroundColor = BaseColor.RED;
//}
//catch (NullReferenceException ex)
//{
// MessageBox.Show(ex.Message);
//}
}
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
try
{
if (cell != null)
{
pdfTable.AddCell(cell.Value.ToString());
}
}
catch (NullReferenceException ex)
{
// MessageBox.Show(ex.Message);
}
}
}
//Exporting to PDF
string folderPath = "Resources/pdf/";
if (!Directory.Exists(folderPath))
{
try
{
Directory.CreateDirectory(folderPath);
}
catch (NullReferenceException ex)
{
MessageBox.Show(ex.Message);
}
}
using (FileStream stream = new FileStream(folderPath + "DataGridViewExport.pdf", FileMode.Create))
{
try
{
Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
pdfDoc.Add(pdfTable);
pdfDoc.Close();
stream.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Reply
Answers (
2
)
can we Trace delegate Call chain by using Delegate object ?
garbage collection?