Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.
Fri Apr 17, 2015 4:56 pm
I have a grid for displaying data in which I have header with two rows and I need different colors and fonts for each header row but font is acting weird.
Code:
- Code: Select all
...
PdfStringFormat centerFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
PdfTrueTypeFont firstHeaderRowFont = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
PdfTrueTypeFont secondHeaderRowFont = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Bold));
PdfTrueTypeFont bodyRowFont = new PdfTrueTypeFont(new Font("Arial", 6f));
string[] dataSource = GetDataSource(records, dateTypeColumnName, dateType);
String[] header = dataSource[0].Split(';');
grid.Columns.Add(header.Length);
PdfGridRow headerRow = grid.Headers.Add(1)[0];
headerRow.Cells[0].Value = tableHeading;
headerRow.Cells[0].Style.Borders = border;
headerRow.Cells[0].StringFormat = centerFormat;
headerRow.Cells[0].Style.Font = firstHeaderRowFont;
headerRow.Cells[0].ColumnSpan = grid.Columns.Count;
headerRow.Cells[0].Style.BackgroundBrush = new PdfSolidBrush(new PdfRGBColor(217, 217, 217));
PdfGridRow headerRow2 = grid.Headers.Add(1)[1];
for (int i = 0; i < header.Length; i++)
{
headerRow2.Cells[i].Value = header[i];
headerRow2.Cells[i].StringFormat = centerFormat;
headerRow2.Cells[i].Style.Borders = border;
headerRow2.Cells[i].Style.Font = secondHeaderRowFont;
headerRow2.Cells[i].Style.Borders = border;
headerRow2.Cells[i].Style.BackgroundBrush = new PdfSolidBrush(new PdfRGBColor(255, 255, 204));
}
...
As you can see from code I set "firstHeaderRowFont" for first header row font and "secondHeaderRowFont" for second row and very often happens that font in first row gets overridden by font in second. I am not sure but I think that is somehow connected with font style because behavior changes if I change styles for "firstHeaderRowFont" and "secondHeaderRowFont" as you can see from attachment.
Login to view the files attached to this post.
-
jbojcic
-
- Posts: 23
- Joined: Mon Apr 13, 2015 3:03 pm
Mon Apr 20, 2015 9:03 am
Hello,
Thanks for your inquiry.
Please set the height of the headerRow. And you can refer to the code below:
headerRow.Height = 15;
If there are any questions, welcome to get it back to us.
Sincerely,
Sweety
E-iceblue support team
-
sweety1
-
- Posts: 539
- Joined: Wed Mar 11, 2015 1:14 am
Mon Apr 20, 2015 9:26 am
I've added that so code is following:
- Code: Select all
...
PdfStringFormat centerFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
PdfTrueTypeFont firstHeaderRowFont = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
PdfTrueTypeFont secondHeaderRowFont = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Bold));
PdfTrueTypeFont bodyRowFont = new PdfTrueTypeFont(new Font("Arial", 6f));
string[] dataSource = GetDataSource(records, dateTypeColumnName, dateType);
String[] header = dataSource[0].Split(';');
grid.Columns.Add(header.Length);
PdfGridRow headerRow = grid.Headers.Add(1)[0];
// ********************* headerRow height is set here ***********************
headerRow.Height = 15;
headerRow.Cells[0].Value = tableHeading;
headerRow.Cells[0].Style.Borders = border;
headerRow.Cells[0].StringFormat = centerFormat;
headerRow.Cells[0].Style.Font = firstHeaderRowFont;
headerRow.Cells[0].ColumnSpan = grid.Columns.Count;
headerRow.Cells[0].Style.BackgroundBrush = new PdfSolidBrush(new PdfRGBColor(217, 217, 217));
PdfGridRow headerRow2 = grid.Headers.Add(1)[1];
for (int i = 0; i < header.Length; i++)
{
headerRow2.Cells[i].Value = header[i];
headerRow2.Cells[i].StringFormat = centerFormat;
headerRow2.Cells[i].Style.Borders = border;
headerRow2.Cells[i].Style.Font = secondHeaderRowFont;
headerRow2.Cells[i].Style.Borders = border;
headerRow2.Cells[i].Style.BackgroundBrush = new PdfSolidBrush(new PdfRGBColor(255, 255, 204));
}
...
But I still get same problem. First row is not centered and font is overridden by second row font. You can see result in the attachment.
Login to view the files attached to this post.
-
jbojcic
-
- Posts: 23
- Joined: Mon Apr 13, 2015 3:03 pm
Mon Apr 20, 2015 1:11 pm
This is what happened when I used same code as above and just added underline to first header row style:
Login to view the files attached to this post.
-
jbojcic
-
- Posts: 23
- Joined: Mon Apr 13, 2015 3:03 pm
Mon Apr 20, 2015 1:16 pm
This happened when I remove bold style from second header row. It seems that now second header row font style got overridden by body font style.
Login to view the files attached to this post.
-
jbojcic
-
- Posts: 23
- Joined: Mon Apr 13, 2015 3:03 pm
Tue Apr 21, 2015 3:58 am
Hello,
Thanks for your information.
I have reproduced your issue. And I have posted the issue to our dev team. We will inform you when it is fixed. Sorry for the inconvenience.
Sincerely,
Sweety
E-iceblue support team
-
sweety1
-
- Posts: 539
- Joined: Wed Mar 11, 2015 1:14 am
Tue Apr 28, 2015 11:44 am
When I changed my grid fonts from:
- Code: Select all
PdfTrueTypeFont firstHeaderRowFont = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
PdfTrueTypeFont secondHeaderRowFont = new PdfTrueTypeFont(new Font("Arial", 7f, FontStyle.Bold));
PdfTrueTypeFont bodyRowFont = new PdfTrueTypeFont(new Font("Arial", 6f));
to
- Code: Select all
PdfFont firstHeaderRowFont = new PdfFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Bold);
PdfFont secondHeaderRowFont = new PdfFont(PdfFontFamily.Helvetica, 7f, PdfFontStyle.Bold);
PdfFont bodyRowFont = new PdfFont(PdfFontFamily.Helvetica, 6f);
this is working fine now.
Login to view the files attached to this post.
-
jbojcic
-
- Posts: 23
- Joined: Mon Apr 13, 2015 3:03 pm
Wed Apr 29, 2015 2:01 am
Hello,
Thanks for your feedback.
I am glad to hear your issue is resolved.
Please feel free to contact us, if you have any questions or needs. We are here for help.
Sincerely,
Sweety
E-iceblue support team
-
sweety1
-
- Posts: 539
- Joined: Wed Mar 11, 2015 1:14 am