Jitendra Sharma

Jitendra Sharma

  • 1.3k
  • 469
  • 27.8k

Export data in pdf in window application

Jan 11 2017 4:12 AM
Sir
 
i am sharing export datagridview to pdf code and datagridview structure also
now i want last two column not print like edit or print only convert required column
that how to do  
 
all colum 8 but two is edit or print so i dont want print or export last two print or edit please  
 
 
if (result == DialogResult.Yes)
{
SaveFileDialog savefile = new SaveFileDialog();
// set a default file name
savefile.FileName = "PO.pdf";
// set filters - this can be done in properties as well
savefile.Filter = "Text files (*.pdf)|*.pdf|All files (*.*)|*.*";
if (savefile.ShowDialog() == DialogResult.OK)
{
//Creating iTextSharp Table from the DataTable data
PdfPTable pdfTable = new PdfPTable(dtgrdvwsalepo.ColumnCount);
pdfTable.DefaultCell.Padding = 4;
pdfTable.WidthPercentage = 100;
pdfTable.HorizontalAlignment = Element.ALIGN_MIDDLE;
pdfTable.DefaultCell.BorderWidth = 1;
// Adding Header row
foreach (DataGridViewColumn column in dtgrdvwsalepo.Columns)
{
PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText));
cell.BackgroundColor = new iTextSharp.text.Color(240, 240, 240);
pdfTable.AddCell(cell);
}
//Adding DataRow
foreach (DataGridViewRow row in dtgrdvwsalepo.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
pdfTable.AddCell(cell.Value.ToString());
}
}
//Exporting to PDF
using (FileStream stream = new FileStream(savefile.FileName, FileMode.Create))
{
Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
pdfDoc.Add(pdfTable);
pdfDoc.Close();
stream.Close();
}
MessageBox.Show("Your pdf generated successfully!");
}
 

Attachment: scrrenshot.rar

Answers (3)