Unable to change font on pdf export header.

Hi,

No matter what I do it always seems to print the header using a weird bold font.

I have included the screen shot . Here is my code sample:

    public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)

    {

        if (args.Item.Id == "Grid_pdfexport") //Id is combination of Grid's ID and itemname

        {

            PdfFont font = new Syncfusion.PdfExport.PdfStandardFont(Syncfusion.PdfExport.PdfFontFamily.TimesRoman, 10);

            PdfGridFont gridFont = new PdfGridFont() { FontStyle = PdfFontStyle.Regular, FontFamily = font };

            var headerContents = new List<PdfHeaderFooterContent>();

            var headerItem = new PdfHeaderFooterContent()

            {

                Type = ContentType.Image,

                Src = LogoSrcJPG,

                Position = new PdfPosition() { X = 20, Y = 0 },

                Size = new PdfSize() { Height = logoSize.Height/10, Width = logoSize.Width/10 }

            };

            headerContents.Add(headerItem);


            headerItem = new PdfHeaderFooterContent()

            {

                Type = ContentType.Text,

                Value = ViewModel.CompanyName,

                Position = new PdfPosition() { X = 300, Y =90},

                Style = new PdfContentStyle() { FontSize=14}


            };


            headerContents.Add(headerItem);`


            headerItem = new PdfHeaderFooterContent()

            {

                Type = ContentType.Text,

                Value = "Date: "+DateTime.Today.ToShortDateString(),

                Position = new PdfPosition() { X = 580, Y = 45 },

                Style = new PdfContentStyle()

                {

                    FontSize = 12,

                    Font = gridFont

                }


            };


            headerContents.Add(headerItem);

            PdfHeader pdfHeader = new PdfHeader()

            {

                FromTop = 0,

                Height = 130,

                Contents = headerContents

            };

            var exportProperties = new PdfExportProperties();

            exportProperties.FileName = ViewModel.CompanyName+"-statement.pdf";

            exportProperties.Header = pdfHeader;

            await this.StatementGrid.ExportToPdfAsync(exportProperties);

        } 


Attachment: Screenshot_20240927_153012_20a588f4.zip

1 Reply

PS Prathap Senthil Syncfusion Team September 30, 2024 11:33 AM UTC

Hi Chris,

Based on your requirements, we suggest using the TextBrush color to achieve the desired outcome. Kindly refer to the code snippet and sample provided below for your reference.

@using Syncfusion.Blazor.Grids

@using Syncfusion.PdfExport

 

<SfGrid ID="Grid" @ref="DefaultGrid" DataSource="@Orders" Toolbar="@(new List<string>() { "PdfExport" })" AllowPdfExport="true" AllowPaging="true">

    <GridEvents OnToolbarClick="ToolbarClickHandler" TValue="Order"></GridEvents>

</SfGrid>

 

@code {

    private SfGrid<Order> DefaultGrid;

    public List<Order> Orders { get; set; }

 

    public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)

    {

        if (args.Item.Id == "Grid_pdfexport")  //Id is combination of Grid's ID and itemname

        {

            PdfExportProperties ExportProperties = new PdfExportProperties();

          

               

 

            PdfFont font = new Syncfusion.PdfExport.PdfStandardFont(Syncfusion.PdfExport.PdfFontFamily.TimesRoman, 10);

 

            PdfGridFont gridFont = new PdfGridFont() { FontStyle = PdfFontStyle.Regular, FontFamily = font };

            var headerContents = new List<PdfHeaderFooterContent>();

 

         

 

 

            var headerItem = new PdfHeaderFooterContent()

 

                {

 

                    Type = ContentType.Text,

 

                   

 

                    Value = "CompanyName",

 

                    Position = new PdfPosition() { X = 300, Y = 90 },

 

                   Style = new PdfContentStyle() { FontSize = 12, TextBrushColor = "#000000" }

 

 

 

                };

 

 

 

            headerContents.Add(headerItem);

 

 

 

        headerItem = new PdfHeaderFooterContent()

 

            {

 

                Type = ContentType.Text,

 

               

 

                Value = "Date: " + DateTime.Today.ToShortDateString(),

 

                Position = new PdfPosition() { X = 580, Y = 45  },

                Style = new PdfContentStyle() { TextBrushColor = "#000000", FontSize = 12 }

 

 

 

            };

            headerContents.Add(headerItem);

 

            PdfHeader pdfHeader = new PdfHeader()

            {

 

                    FromTop = 0,

 

                    Height = 130,

 

                    Contents = headerContents

 

            };

 

         

            ExportProperties.Header = pdfHeader;

 

            await this.DefaultGrid.PdfExport(ExportProperties);

        }

    }

}


Sample:
https://blazorplayground.syncfusion.com/embed/BtrptkKNqYCTMnRZ?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5


Reference:
https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PdfContentStyle.html#Syncfusion_Blazor_Grids_PdfContentStyle_TextBrushColor


Regards,
Prathap Senthil


Loader.
Up arrow icon