BoldSign®Effortlessly integrate e-signatures into your app with the BoldSign® API. Create a sandbox account!
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?
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 }
}
}
};
}
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
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
Thank you so much for this!
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.
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:
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
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:
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
Here's the best I can do.
The model class for the pdf report data:
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:
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:
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.
I was able to get the footer to show after changing the footer height from 12 to 15.
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