Goran Bibic

Goran Bibic

  • 480
  • 2.9k
  • 200.7k

Column type ITEXTSHARP C#

May 2 2018 12:09 PM
I have problem with output result...
Column have value 16.2.2018 00:00:00
 
I need value  16.2.2018
 
Sql column type  is DATE
 
Need help
  1. private void button2_Click(object sender, EventArgs e) //pdf print button  
  2.         {  
  3.             //Creating iTextSharp Table from the DataTable data  
  4.             //Console.WriteLine(drzaveDataGridView.ColumnCount); test za itext sharp  
  5.             PdfPTable pdfTable = new PdfPTable(mktestprobaDataGridView.ColumnCount);  
  6.             pdfTable.DefaultCell.Padding = 3;  
  7.             pdfTable.WidthPercentage = 100;  
  8.             pdfTable.HorizontalAlignment = Element.ALIGN_LEFT;  
  9.             pdfTable.DefaultCell.BorderWidth = 1;  
  10.             float[] sirina = new float[] { 20f, 25f, 45f, 56f, 43f };  
  11.             pdfTable.SetWidths(sirina);  
  12.             BaseFont bfCalibri = BaseFont.CreateFont("c:\\windows\\fonts\\calibri.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);  
  13.             iTextSharp.text.Font calibri = new iTextSharp.text.Font(bfCalibri, 8);  
  14.   
  15.   
  16.             //Adding Header row  
  17.             foreach (DataGridViewColumn column in mktestprobaDataGridView.Columns)  
  18.             {  
  19.                 PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText));  
  20.                 //cell.BackgroundColor = new iTextSharp.text.Color(240, 240, 240);  
  21.                 pdfTable.AddCell(cell);  
  22.             }  
  23.   
  24.             //Adding DataRow  
  25.             foreach (DataGridViewRow row in mktestprobaDataGridView.Rows)  
  26.             {  
  27.   
  28.                 foreach (DataGridViewCell cell in row.Cells)  
  29.                 {  
  30.                     pdfTable.AddCell(cell.Value.ToString());  
  31.                 }  
  32.             }  
  33.   
  34.             //Exporting to PDF  
  35.   
  36.             string folderPath = "C:\\PDFs\\";  
  37.             if (!Directory.Exists(folderPath))  
  38.             {  
  39.                 Directory.CreateDirectory(folderPath);  
  40.             }  
  41.             using (FileStream stream = new FileStream(folderPath + "Drzave.pdf", FileMode.Create))  
  42.             {  
  43.                 iTextSharp.text.Font calibriTitle = new iTextSharp.text.Font(bfCalibri, 18);  
  44.                 iTextSharp.text.Font calibriSubTitle = new iTextSharp.text.Font(bfCalibri, 14);  
  45.   
  46.                 Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);  
  47.                 PdfWriter.GetInstance(pdfDoc, stream);  
  48.                 pdfDoc.Open();  
  49.                // pdfDoc.Add(new Paragraph(korisnik_programa));  
  50.               //  pdfDoc.Add(new Paragraph(adresa));  
  51.                 pdfDoc.Add(pdfTable);  
  52.                 pdfDoc.Close();  
  53.                 stream.Close();  
  54.                 System.Diagnostics.Process.Start(folderPath + "Drzave.pdf");  
  55.             }  
  56.         }  
  57.      
Result
 

Answers (4)