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
Draw multiple rectangle with Itextsharp pdf C#
Apr 14 2020 3:57 AM
private void PrintButton_Click(object sender, EventArgs e)
{
PdfPTable pdfTable = new PdfPTable(3);
pdfTable.DefaultCell.Padding = 3;
pdfTable.WidthPercentage = 100;
pdfTable.HorizontalAlignment = Element.ALIGN_LEFT;
pdfTable.DefaultCell.BorderWidth = 1;
BaseFont bfCalibri = BaseFont.CreateFont(
"c:\\windows\\fonts\\calibri.ttf"
, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
iTextSharp.text.Font calibri = new iTextSharp.text.Font(bfCalibri, 12);
iTextSharp.text.Font calibri6 = new iTextSharp.text.Font(bfCalibri, 10);
//Adding DataRow
foreach (DataGridViewRow row
in
ListDataGridView.
Rows
)
{
PdfPCell pdfCell = new PdfPCell();
PdfPTable tmpTable = new PdfPTable(1);
tmpTable.WidthPercentage = 100;
PdfPCell tmpCell = new PdfPCell();
tmpCell.FixedHeight = 60;
tmpCell.HorizontalAlignment = Element.ALIGN_CENTER;
tmpCell.VerticalAlignment = Element.ALIGN_MIDDLE;
tmpCell.BorderWidth = 1;
//tmpTable.AddCell(tmpCell);
tmpTable.DefaultCell.BorderWidth = 0;
tmpTable.DefaultCell.VerticalAlignment = Element.ALIGN_TOP;
tmpTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
tmpTable.AddCell(new Paragraph(row.Cells[4].Value.ToString().ToUpper(), calibri));
pdfCell.AddElement(tmpTable);
pdfTable.AddCell(pdfCell);
}
var tempFiles = new System.CodeDom.Compiler.TempFileCollection();
{
string file = tempFiles.AddExtension(
"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, 18);
iTextSharp.text.Font calibriSubTitle = new iTextSharp.text.Font(bfCalibri, 14);
iTextSharp.text.Font calibriTextBold = new iTextSharp.text.Font(bfCalibri, 14, iTextSharp.text.Font.BOLD);
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.
Open
();
pdfDoc.
Add
(pdfTable);
writer.CloseStream =
false
;
pdfDoc.
Close
();
stream.
Close
();
System.Diagnostics.Process p = System.Diagnostics.Process.Start(stream.
Name
);
}
}
}
Result is
I have 3 row in my table.
I need next:
1) To be just selected row on print
2) To make some textbox and put inside some number exp 6 and to be on pdf 6 selected row boxex added
Reply
Answers (
1
)
operator += cannot be applied with string and void asp.net
Excel download restriction