When long text doesn't fit on one page in a cell, its adjacent cell text is clipped

It is expected that "Max Height" text renders in a left cell. Instead there is nothing. This happens only when large cell spand more than one page.


        public static void LongText()

        {

            using (PdfDocument pdfDocument = new PdfDocument())

            {

                const float pageMargins = 15;


                var section = pdfDocument.Sections.Add();

                var pdfPage = section.Pages.Add();

                section.PageSettings.SetMargins(pageMargins);

                pdfDocument.PageSettings.SetMargins(pageMargins);


                // Create root grid

                PdfGrid rootGrid = new PdfGrid();


                var col = rootGrid.Columns.Add();

                col.Width = PdfPageSize.A4.Width - 2 * pageMargins;

                var row = rootGrid.Rows.Add();

                var cell = row.Cells[0];

                cell.Style.Borders.All = PdfPens.Aquamarine;


                // Create grid with 2 rows

                const float padding = 3;

                cell.Style.CellPadding = new PdfPaddings(padding, padding, padding, padding);

                PdfGrid grid = new PdfGrid();

                grid.Columns.Add().Width = col.Width / 2 - padding;

                grid.Columns.Add().Width = col.Width / 2 - padding;

                cell.Value = grid;


                void SetCell(int rowIndex, int cellIndex, string text, int colSpan = 1)

                {

                    PdfGridCell _cell = grid.Rows[rowIndex].Cells[cellIndex];

                    _cell.Style.CellPadding = cell.Style.CellPadding;

                    _cell.Style.Borders.All = new PdfPen(Color.Black, 0.5f);

                    _cell.ColumnSpan = colSpan;

                    _cell.Value = text;

                }

                int i = grid.Rows.Count;

                int maxRows = 5;

                for (; i < maxRows; i++)

                {

                    grid.Rows.Add();

                    SetCell(i, 0, "Text");

                    SetCell(i, 1, "Text");

                }

                grid.Rows.Add();

                var lastRow = grid.Rows.Last();

                lastRow.Cells[0].Value = "Max Height";

                lastRow.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Bottom);

                lastRow.Cells[1].Value = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";


                var width = grid.Columns[1].Width - cell.Style.CellPadding.Top - cell.Style.CellPadding.Bottom;

                UpdateRowHeight2(grid.Rows[0],

                    grid.Rows[0].Cells[1].Value.ToString(), width);


                i = grid.Rows.Count;

                maxRows = i + maxRows;

                for (; i < maxRows; i++)

                {

                    grid.Rows.Add();

                    SetCell(i, 0, "Text");

                    SetCell(i, 1, "Text");

                }


                var layoutFormat = new PdfLayoutFormat { Break = PdfLayoutBreakType.FitPage, Layout = PdfLayoutType.Paginate };

                rootGrid.Draw(pdfPage, new PointF(0, 0), layoutFormat);


                //Save the document

                string fileName = $"File{DateTime.Now.Ticks}.pdf";

                pdfDocument.Save(fileName);

                //Close the document

                pdfDocument.Close(true);

                Process.Start(fileName);

            }

        }

        private static void UpdateRowHeight2(PdfGridRow row, string text, float columnWidth)

        {

            if (string.IsNullOrEmpty(text))

            {

                return;

            }

            var font = new PdfStandardFont(PdfFontFamily.Helvetica, 8f);

            SizeF size = font.MeasureString(text.Replace("\n", string.Empty).Replace("\r", string.Empty));

            var newLines = text.Count(x => x == '\n');

            var extraLines = newLines > 1 ? newLines - 2 : 0;

            float lineCount = size.Width / columnWidth + 1 + extraLines;

            float heightNeeded = (size.Height + 1) * lineCount;

            if (row.Height < heightNeeded)

            {

                row.Height = heightNeeded;

            }

        }




3 Replies

GK Gowthamraj Kumar Syncfusion Team February 21, 2022 02:58 PM UTC

Hi umlprog, 
 
We were able to reproduce the reported issue with provided code snippet on our end. Currently, we are validating on this and we will update the further details on February 23rd 2022. 
 
Regards, 
Gowthamraj K 



GK Gowthamraj Kumar Syncfusion Team February 23, 2022 01:38 PM UTC

Hi umlprog, 
 
We confirmed the issue “Text cutoff issue occurs while paginating the long text in Pdf grid cell” as a defect in our product. We will include the fix for this issue in our weekly NuGet release, which will be available on March 8th, 2022. 
  
Please use the below feedback link to track the status of the reported bug. 
  
Note: If you require patch for the reported issue in any of our Essential Studio Main or SP release version, then kindly let us know the version, so that we can provide a patch in that version based on our SLA policy. 
  
Please let us know if you need any further assistance in this. 
 
Regards, 
Gowthamraj K 



GK Gowthamraj Kumar Syncfusion Team March 8, 2022 10:11 AM UTC

Hi umlprog, 

We have included the fix for the reported issue “Text cutoff issue occurs while paginating the long text in Pdf grid cell” in our latest weekly NuGet release (v19.4.0.55). Please use the below link to download our latest weekly NuGet,      
   
Please let us know if you have any concerns on this   

Regards, 
Gowthamraj K 


Loader.
Up arrow icon