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.1k
Pdf sum column from table itext sharp
Apr 8 2018 1:56 AM
Report Itextsharp pdf
The application is for record workers. I need to make a pdf report for all the workers listed in the table
Exp ...
ROW 1 Worker1 coming time out time work overtime
ROW 2 Worker2 coming time out time work overtime
ROW 3 Worker3 coming time out time work overtime
ROW 4 Worker3 coming time out time work overtime
ROW 5 Worker2 coming time out time work overtime
ROW 6 Worker1 coming time out time work overtime
ROW 7 Worker3 coming time out time work overtime
ROW 8 Worker3 coming time out time work overtime
I need report
1 Worker1 work ours sum overtime sum
2 Worker2 work ours sum overtime sum
2 Worker3 work ours sum overtime sum
//Creating iTextSharp Table from the DataTable data
PdfPTable pdfTable =
new
PdfPTable(prijava_radnikaDataGridView.ColumnCount - 5);
pdfTable.DefaultCell.Padding = 3;
pdfTable.WidthPercentage = 100;
pdfTable.HorizontalAlignment = Element.ALIGN_CENTER;
pdfTable.DefaultCell.BorderWidth = 1;
float
[] widths =
new
float
[] { 18f, 40f, 35f, 35f, 25f, 25f };
pdfTable.SetWidths(widths);
BaseFont bfCalibri = BaseFont.CreateFont(
"c:\\windows\\fonts\\calibri.ttf"
, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
iTextSharp.text.Font calibri =
new
iTextSharp.text.Font(bfCalibri, 10, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.WHITE);
iTextSharp.text.Font calibri2 =
new
iTextSharp.text.Font(bfCalibri, 9);
//Adding Header row
foreach (DataGridViewColumn column in prijava_radnikaDataGridView.Columns)
{
if
(column.Index == 0 || column.Index == 5 || column.Index == 6 || column.Index == 7 || column.Index == 10)
{
}
else
{
PdfPCell cell =
new
PdfPCell(
new
Phrase(column.HeaderText, calibri));
cell.BackgroundColor =
new
BaseColor(89, 135, 178);
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
pdfTable.AddCell(cell);
}
}
//Adding DataRow
foreach (DataGridViewRow row in prijava_radnikaDataGridView.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
if
(cell.ColumnIndex == 0 || cell.ColumnIndex == 5 || cell.ColumnIndex == 6 || cell.ColumnIndex == 7 || cell.ColumnIndex == 10)
{
}
else
{
pdfTable.AddCell(
new
PdfPCell(
new
Phrase(cell.Value.ToString(), calibri2)));
}
}
}
//Exporting to PDF
string folderPath =
"C:\\PDFs\\"
;
if
(!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
string file = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() +
".pdf"
;
using
(FileStream stream = File.OpenWrite(file))
{
var attributes = File.GetAttributes(file);
File.SetAttributes(file, attributes | FileAttributes.Temporary);
iTextSharp.text.Font calibriTitle =
new
iTextSharp.text.Font(bfCalibri, 16);
iTextSharp.text.Font calibriSubTitle =
new
iTextSharp.text.Font(bfCalibri, 12);
iTextSharp.text.Font calibriTextBold =
new
iTextSharp.text.Font(bfCalibri, 12, iTextSharp.text.Font.BOLD);
Document pdfDoc =
new
Document(PageSize.A4, 10f, 10f, 10f, 10f);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
pdfDoc.Add(
new
Paragraph(
"Company name"
, calibriTitle));
pdfDoc.Add(
new
Paragraph(
" "
, calibriTitle));
pdfDoc.Add(
new
Paragraph(
"Evidencija radnika: "
+ textBox1.Text, calibriSubTitle));
if
(checkBox1.Checked ==
true
)
{
pdfDoc.Add(
new
Paragraph(
"Od "
+ dateTimePicker1.Value.ToString(
"dd.MM.yyyy."
) +
" do "
+ dateTimePicker2.Value.ToString(
"dd.MM.yyyy."
), calibriSubTitle));
}
pdfDoc.Add(
new
Paragraph(
"\n"
, calibriSubTitle));
pdfDoc.Add(pdfTable);
Paragraph par =
new
Paragraph(
new
Chunk(
new
iTextSharp.text.pdf.draw.LineSeparator(0.0F, 40.0F, BaseColor.BLACK, Element.ALIGN_RIGHT, 1)));
pdfDoc.Add(par);
par =
new
Paragraph(
"Sati: "
+ sum.ToString() +
"\t Prekovremeni: "
+ overtimeSum.ToString() +
"\n"
);
par.Alignment = Element.ALIGN_RIGHT;
pdfDoc.Add(par);
par =
new
Paragraph(
"UKUPNO: "
+ (sum + overtimeSum).ToString() +
" h"
, calibriTextBold);
par.Alignment = Element.ALIGN_RIGHT;
pdfDoc.Add(par);
writer.CloseStream =
false
;
pdfDoc.Close();
stream.Close();
System.Diagnostics.Process p = System.Diagnostics.Process.Start(stream.Name);
}
}
Reply
Answers (
0
)
is there any javascript to c# converter ? (not for unity)
How To Merge Two SQL Tables Into Third Table with All Rows?