PDF Export Cutting off Header Text

I have an application with several data grids that need to export to PDF. Some of these pdf's will have very long headers/titles and the text is being cutting off the page. Is there a way to wrap the text and have it display on multiple lines?


PDF_Screenshot_HeaderTextCutOff.png


Code:

    private PdfHeader BuildPdfHeader()

    {

        return new PdfHeader

            {

                FromTop = 0,

                Height = 100,

                Contents = new List<PdfHeaderFooterContent>

            {

                new()

                {

                    Type = ContentType.Text,

                    Value = "Initial Health Assessment",

                    Position = new PdfPosition { X = 0, Y = 0 },

                    Style = new PdfContentStyle { TextBrushColor = "#000000", FontSize = 26, HAlign = PdfHorizontalAlign.Left }

                },

                new()

                {

                    Type = ContentType.Text,

                    Value = AssessmentSearchResults?.FirstOrDefault()?.IpaDescription,

                    Position = new PdfPosition { X = 0, Y = 50 },

                    Style = new PdfContentStyle { TextBrushColor = "#000000", FontSize = 15, HAlign = PdfHorizontalAlign.Left }

                }

            }

            };

    }


9 Replies 1 reply marked as answer

PS Prathap Senthil Syncfusion Team February 11, 2025 01:11 PM UTC

Hi Lorna Grajek,


We have confirmed that this is an issue and logged a defect report titled  “PDF export cutting off header text in pdfHeaderFooterContent in the grid” This fix will be included in our weekly patch release, which is expected to be rolled out on February 25th, 2025. You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.    
 
PDF export cutting off header text in pdfHeaderFooterContent in the grid in Blazor | Feedback Portal

Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization”

We will get back to you once the release is rolled out. Thanks for your understanding.

Regards,
Prathap Senthil



GR Guhanathan Ramanathan Syncfusion Team February 25, 2025 01:37 PM UTC

Hi  Lorna Grajek,


Thanks for your patience,


We are glad to announce that, we have included the fix for the issue  “PDF export cutting off header text in pdfHeaderFooterContent in the grid” in our 28.2.7 release.  So please upgrade to our latest version of Syncfusion NuGet package to resolve the reported issue. Please find the NuGet package for the latest fixes and features below.

 

NuGet : https://www.nuget.org/packages/Syncfusion.Blazor.Grid

Root cause : When exporting a PDF with pdfHeaderFooterContent, the DrawText method is triggered, in which the size and position properties of pdfHeaderFooterContent are assigned. If the size property is not provided, the default DrawString method is executed with a width and height of Zero.


Action Taken: Change the default DrawString method to the DrawString method with a  RectangleF   parameter. Pass the element's width and height values to the  RectangleF  object, along with the position. When the size property is provided, pass the width and height to the RectangleF object, along with the position.

Regards,

Guhanathan R


Marked as answer

LG Lorna Grajek February 26, 2025 04:27 PM UTC

Thank you so much for this!



PS Prathap Senthil Syncfusion Team February 27, 2025 06:38 AM UTC

Thanks for the update. We are happy to hear that the issue has been resolved on your end. Please feel free to reach out if you have any further queries regarding this issue.




JT Justin Turner March 25, 2025 09:59 PM UTC

I think this update (28.2.7) broke the footer for PDF generation.

In 28.2.6, this could would work and  display all three footers:

Snippet
var footerContentList = new List<PdfHeaderFooterContent>
            {
                new()
                {
                    Type = ContentType.Text,
                    Value = $"Print Date: {DateTime.Now.ToString("f")}",
                    Position = new PdfPosition { X = 0, Y = 0 },
                    Style = new PdfContentStyle { TextBrushColor = "#00000", FontSize = 8, HAlign = PdfHorizontalAlign.Left }
                },
                new()
                {
                    Type = ContentType.Text,
                    Value = "Some text here",
                    Position = new PdfPosition { X = 640, Y = 0 },
                    Style = new PdfContentStyle { TextBrushColor = "#00000", FontSize = 8, HAlign = PdfHorizontalAlign.Right }
                },
                new()
                {
                    Type = ContentType.PageNumber,
                    PageNumberType = PdfPageNumberType.Arabic,
                    Position = new PdfPosition { X = 450, Y = 0 },
                    Style = new PdfContentStyle
                    {
                        TextBrushColor = "#000000",
                        FontSize = 8, HAlign = PdfHorizontalAlign.Center
                    }
                }
            };

In 28.2.7, on the last footer, the page number, is showing



GR Guhanathan Ramanathan Syncfusion Team March 26, 2025 11:48 AM UTC

Hi Justin Turner,

Greetings from Syncfusion,


While reviewing your query, We are unable to reproduce the reported issue when testing in version 28.2.7 and the latest version. For your reference, we have shared a simple sample. To proceed with investigating the reported problem, we would need some additional clarification from your end. Please share the below details to proceed further at our end.


Screenshot:

Image_7376_1742989625118


  • Share us the full Grid code snippet and model class.
  • Share a video demonstration of the issue with a detailed explanation. This will greatly assist us in understanding the problem.
  • Please provide a simple sample that reproduces the issue with duplicate data, or modify the mentioned sample to reproduce the issue.
  • Additionally, try clearing the bin, obj, and .vs folders, as well as the NuGet and browser caches, to see if the issue persists.

Above-requested details will be very helpful in validating the reported query at our end and providing a solution as early as possible. Thanks for your understanding.


Regards,

Guhanathan R




Attachment: Sample_9f6a8787.zip


JT Justin Turner March 26, 2025 12:58 PM UTC

Here's the best I can do.


The model class for the pdf report data:

Snippet
    public class MemberHospitalizationsViewModel
{
    public DateTime AdmitDate { get; set; }
    public string AdmitDiagnosis { get; set; }
    public string AuthorizationURL { get; set; }
    public string Facility { get; set; }
    public string IPA { get; set; }
    public string MemberDBKey { get; set; }
    public string MemberDisplayID { get; set; }
    public string MemberID { get; set; }
    public string MemberName { get; set; }
    public string PrimaryCarePhysician { get; set; }
    public string PrimaryCarePhysicianProvID { get; set; }
    public string ReferralNumber { get; set; }
}

The Toolbar Click Handler:

Snippet
public async Task ToolbarClickHandler(ClickEventArgs args)
    {
        try
        {
            if (MembersHospitalizations == null || MembersHospitalizations.Count == 0)
            {
                return;
            }
 
            if (args.Item.Id == "Grid_pdfexport")
            {
                var pdfReport = new PDFGridReportHelper(MembersHospitalizations.FirstOrDefault()?.IPA, "New / Recent Member Hospitalizations");
                var selected = await MembersHospitalizationsGrid.GetSelectedRecordsAsync();
                pdfReport.ExportProperties.DataSource = selected.Count > 0 ? selected : MembersHospitalizations;
                pdfReport.ExportProperties.FileName = $"MemberHospitalizations_{DateTime.Now:yyyyMMdd}.pdf";
                pdfReport.ExportProperties.Columns = new List<GridColumn>
                    {
                        new() { Field = "MemberName", HeaderText = "Member Name", TextAlign = TextAlign.Left, Width = "118" },
                        new() { Field = "ReferralNumber", HeaderText = "Referral Number", TextAlign = TextAlign.Left, Width = "118" },
                        new() { Field = "AdmitDate", HeaderText = "Admit Date", Type = ColumnType.Date, Format = "d", TextAlign = TextAlign.Left, Width = "60" },
                        new() { Field = "AdmitDiagnosis", HeaderText = "Admit Diagnosis", TextAlign = TextAlign.Left, Width = "138" },
                        new() { Field = "Facility", HeaderText = "Facility", TextAlign = TextAlign.Left, Width = "138" },
                        new() { Field = "PrimaryCarePhysician", HeaderText = "PCP", TextAlign = TextAlign.Left, Width = "136" }
                    };
                await MembersHospitalizationsGrid.ExportToPdfAsync(pdfReport.ExportProperties);
            }
        }
        catch (Exception e)
        {
            await ErrorService.ErrorInsert(e);
            NavManager.NavigateTo("/Error");
        }
    }

And the PDFGridReportHelper class:

Snippet
public class PDFGridReportHelper
    {
        public PdfExportProperties ExportProperties { get; set; }
 
        public PDFGridReportHelper(string IPA, string title)
        {
            var headerContentList = new List<PdfHeaderFooterContent>
            {
                new()
                {
                    Type = ContentType.Text,
                    Value = title,
                    Position = new PdfPosition { X = 0, Y = 0 },
                    Style = new PdfContentStyle { TextBrushColor = "#00000", FontSize = 26, HAlign = PdfHorizontalAlign.Left }
 
                },
                new()
                {
                    Type = ContentType.Text,
                    Value = IPA,
                    Position = new PdfPosition { X = 0, Y = 50 },
                    Style = new PdfContentStyle { TextBrushColor = "#00000", FontSize = 15, HAlign = PdfHorizontalAlign.Left }
                }
            };
 
            var footerContentList = new List<PdfHeaderFooterContent>
            {
                new()
                {
                    Type = ContentType.Text,
                    Value = $"Print Date: {DateTime.Now.ToString("f")}",
                    Position = new PdfPosition { X = 0, Y = 0 },
                    Style = new PdfContentStyle { TextBrushColor = "#00000", FontSize = 8, HAlign = PdfHorizontalAlign.Left }
                },
                new()
                {
                    Type = ContentType.Text,
                    Value = "CONFIDENTIAL  Report provided by Conifer Value-Based Care",
                    Position = new PdfPosition { X = 640, Y = 0 },
                    Style = new PdfContentStyle { TextBrushColor = "#00000", FontSize = 8, HAlign = PdfHorizontalAlign.Right }
                },
                new()
                {
                    Type = ContentType.PageNumber,
                    PageNumberType = PdfPageNumberType.Arabic,
                    Position = new PdfPosition { X = 450, Y = 0 },
                    Style = new PdfContentStyle
                    {
                        TextBrushColor = "#000000",
                        FontSize = 8, HAlign = PdfHorizontalAlign.Center
                    }
                }
            };
 
            var theme = new PdfTheme
            {
                Header = new PdfThemeStyle
                {
                    Bold = true,
                    FontName = "Roboto",
                    FontColor = "#000000"
                },
                Record = new PdfThemeStyle
                {
                    Bold = false,
                    FontName = "Roboto",
                    FontColor = "#000000",
                    FontSize = 8
                }
 
            };
 
            var header = new PdfHeader
            {
                FromTop = 0,
                Height = 100,
                Contents = headerContentList
 
            };
 
            var footer = new PdfFooter
            {
                FromBottom = 0,
                Height = 12,
                Contents = footerContentList
            };
 
            ExportProperties = new PdfExportProperties
            {
                PageOrientation = PageOrientation.Landscape,
                Header = header,
                Footer = footer,
                Theme = theme,
                IsRepeatHeader = true,
                BeginCellLayout = BeginCellEvent,
                DisableAutoFitWidth = true
            };
 
        }
 
        public void BeginCellEvent(object sender, PdfGridBeginCellLayoutEventArgs args)
        {
            var brush = new PdfSolidBrush(new PdfColor(Color.White));
            var backgroundBrush = new PdfSolidBrush(new PdfColor(Color.Black));
            args.Graphics.Save();
 
            if (args.IsHeaderRow)
            {
                args.Style = new PdfGridCellStyle
                {
                    BackgroundBrush = backgroundBrush,
                    TextBrush = brush,
                    Borders = new PdfBorders
                    {
                        Bottom = new PdfPen(Color.Transparent, 0),
                        Left = new PdfPen(Color.Transparent, 0),
                        Right = new PdfPen(Color.Transparent, 0),
                        Top = new PdfPen(Color.Transparent, 0)
                    },
                    CellPadding = new PdfPaddings(3, 3, 1, 1)
                };
            }
            else
            {
                args.Style = new PdfGridCellStyle
                {
                    Borders = new PdfBorders
                    {
                        Bottom = new PdfPen(Color.Black, 1),
                        Left = new PdfPen(Color.Transparent, 0),
                        Right = new PdfPen(Color.Transparent, 0),
                        Top = new PdfPen(Color.Transparent, 0)
                    },
                    CellPadding = new PdfPaddings(3, 3, 1, 1)
                };
            }
            args.Graphics.Restore();
        }
    }

I've also attached an example screen snip of the generated PDF with redacted data.


Image_8075_1742993897705



JT Justin Turner March 26, 2025 04:58 PM UTC

I was able to get the footer to show after changing the footer height from 12 to 15.



GR Guhanathan Ramanathan Syncfusion Team March 27, 2025 12:09 PM UTC

Hi Justin Turner,

We are glad to hear that you have resolved the issue on your own. Please get back to us if you have further queries.


Regards,
Guhanathan R


Loader.
Up arrow icon