PDF creation ITextSharp how to rename field names
Pulling column names from a database. Column names aren't user friendly so was wanting to rename them on the pdf. Is there a way to do this?
foreach (DataColumn column in dt.Columns)
{
PdfPCell pCell = new PdfPCell(new Phrase(column.ColumnName, TableHeaderFont));
pCell.BackgroundColor = BaseColor.BLUE;
pCell.Padding = 6;
contentTable.AddCell(pCell);
}
this is the code I'm using to pull the column names.
Related Article: Return blank input field with a value help
is a solved Web Development discussion thread by double_cola that has 1 reply, was last updated 6 months ago and has been tagged with the keywords: input, field, php, drag, and, drop, pdf.
coder91
Junior Poster in Training
94 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Just replace column.ColumnName with the names you want. I suggest using a dictionary to use for the conversion.
pritaeas
Posting Prodigy
9,293 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,462
Skill Endorsements: 86
in the line
PdfPCell pCell = new PdfPCell(new Phrase(column.ColumnName, TableHeaderFont));
Will that not only change the column name off one? or change all columns to the same name?
I thought i might have to do something such as
foreach (DataColumn column in dt.Columns)
{
String NewName = column.ColumnName;
String revisedName = "";
switch (NewName)
{
case "AppRef":
revisedName ="Reference";
break;
default:
break;
etc for rest of columns
}
PdfPCell pCell = new PdfPCell(new Phrase(column.ColumnName, TableHeaderFont));
pCell.BackgroundColor = BaseColor.BLUE;
pCell.Padding = 6;
contentTable.AddCell(pCell);
}
coder91
Junior Poster in Training
94 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
That's kind of what I meant. Just instead of your switch, create a dictionary with the from and to values. Something like this:
var map = new Dictionary<string, string>();
map.Add("AppRef", "Reference");
// Etc.
PdfPCell pCell = new PdfPCell(new Phrase(map[column.ColumnName], TableHeaderFont));
pritaeas
Posting Prodigy
9,293 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,462
Skill Endorsements: 86
O get you now, thank you, i'll try that now.
coder91
Junior Poster in Training
94 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 5 Months Ago by
pritaeas