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
Goran Bibic
482
2.9k
197.8k
Itextsharp PDF c#
Apr 23 2018 4:26 AM
Datetime column format in pdf document
sql column is type date
private
void
button2_Click(object sender, EventArgs e)
{
PdfPTable pdfTable =
new
PdfPTable(testtableDataGridView.ColumnCount);
pdfTable.DefaultCell.Padding = 3;
pdfTable.WidthPercentage = 100;
pdfTable.HorizontalAlignment = Element.ALIGN_LEFT;
pdfTable.DefaultCell.BorderWidth = 1;
pdfTable.DefaultCell.BorderWidth = 1;
float
[] sirina =
new
float
[] { 50f, 90f, 45f, 40f, 40f };
pdfTable.SetWidths(sirina);
BaseFont bfCalibri = BaseFont.CreateFont(
"c:\\windows\\fonts\\calibri.ttf"
, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
iTextSharp.text.Font calibri =
new
iTextSharp.text.Font(bfCalibri, 10);
//Adding Header row
foreach (DataGridViewColumn column in testtableDataGridView.Columns)
{
PdfPCell cell =
new
PdfPCell(
new
Phrase(column.HeaderText, calibri));
cell.BackgroundColor =
new
iTextSharp.text.BaseColor(240, 240, 240);
pdfTable.AddCell(cell);
}
//Adding DataRow
foreach (DataGridViewRow row in testtableDataGridView.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
string yourDateString = testtableDataGridView.Rows[row][dataGridViewTextBoxColumn12].ToString(
"dd/MM/yyyy"
);
PdfPCell cell2 =
new
PdfPCell(
new
Phrase(
new
Chunk(DateTime.Parse(yourDateString).ToShortDateString(), calibri)));
pdfTable.AddCell(cell2);
}
}
//Exporting to PDF
string folderPath =
"C:\\PDFs\\"
;
if
(!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
using
(FileStream stream =
new
FileStream(folderPath +
"Ulazni racun roba.pdf"
, FileMode.Create))
{
iTextSharp.text.Font calibriTitle =
new
iTextSharp.text.Font(bfCalibri, 12);
iTextSharp.text.Font calibriSubTitle =
new
iTextSharp.text.Font(bfCalibri, 10);
Document pdfDoc =
new
Document(PageSize.A4, 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
pdfDoc.Add(pdfTable);
pdfDoc.Close();
stream.Close();
System.Diagnostics.Process.Start(folderPath +
"Ulazni racun roba.pdf"
);
}
}
Error is line 30 Rows.row here... Severity Code Description Project File Line Suppression State
Error CS1503 Argument 1: cannot convert from 'System.Windows.Forms.DataGridViewRow' to 'int'
string yourDateString = testtableDataGridView.Rows[row][dataGridViewTextBoxColumn12].ToString(
"dd/MM/yyyy"
);
Reply
Answers (
5
)
C#, values in xml to combobox
Creating Crystal Report