This is a migrated thread and some comments may be shown as answers.

Can't change default font size on pdf export?

2 Answers 348 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Clive Hoggar
Top achievements
Rank 1
Clive Hoggar asked on 08 Feb 2017, 03:40 PM

Hi

I am exporting a grid to pdf following various examples, and I am using the RadGrid_ItemCreated event successfully to have alternating row styles but I haven't found any way to set the font size.

Existing code is :

 

 Protected Sub FormatGridItem(item As GridItem)
        If TypeOf item Is GridHeaderItem Then
            For Each cell As TableCell In item.Cells
                cell.Style("font-family") = "Arial"
                cell.Style("text-align") = "left"
                cell.Style("vertical-align") = "middle"
            Next
        End If

        ' Dim dataItems As GridItem() = View.GetItems(GridItemType.Item)
        If TypeOf item Is GridDataItem Then
            item.Style("Font-family") = "Arial"
        Select Case item.ItemType

                Case GridItemType.Item
                    item.Style("background-color") = "#DDDDDD"
                    item.Style("Font-size") = "10pt"  ' no effect
                    Exit Select
                Case GridItemType.AlternatingItem
                    item.Style("background-color") = "#FFFFFF"
                    item.Style("Font-size") = "10pt"  ' no effect
                    Exit Select
                Case GridItemType.Header
                    item.Font.Bold = True
                    Exit Select
                Case GridItemType.Footer
                    item.Style("background-color") = "#FFFFFF"
                    Exit Select
            End Select
        End If
    End Sub

 

how can I set the font size? I have tried using px, pt, and em but it does not change.

Please advise. I haven't seen any code on this; maybe it is not possible or has to be done somewhere else entirely.

 

Thanks

 

Clive

 

2 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 10 Feb 2017, 03:17 PM

Hello Clive,

I modified the code of the Export to PDF grid demo by adding this line

item.Style("font-size") = "5px" in the FormatGridItem function and it formatted as expected the font in the generated PDF file.

For your convenience, I recorded a video demonstrating my test: https://www.screencast.com/t/24XNsfWiEeaj

Best regards,
Rumen
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Clive Hoggar
Top achievements
Rank 1
answered on 10 Feb 2017, 05:10 PM

Thanks for your help.

I am using alternating row background colour for the grid and I had to put the item.style code in both GridItemType.Item and GridItemType.AlternatingItem to make it work:

Select Case item.ItemType

              Case GridItemType.Item

                  item.Style("background-color") = "#DDDDDD"

     item.Style("Font-size") = "0.8em"

                    Exit Select
                Case GridItemType.AlternatingItem
                    item.Style("background-color") = "#FFFFFF"
                    item.Style("Font-size") = "0.8em"
                    Exit Select
                Case GridItemType.Header
                    item.Font.Bold = True
                    Exit Select
                Case GridItemType.Footer
                    item.Style("background-color") = "#FFFFFF"
                    Exit Select
            End Select

 

 

Tags
Grid
Asked by
Clive Hoggar
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Clive Hoggar
Top achievements
Rank 1
Share this question
or