Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Nov 20, 2019 10:03 am

Hi I am outputting text into a grid. Sometimes the text is quite long but the cell just cuts off the text out side the box.

How do I wrap the text so that the cell height changes to fit the length of the string?

license.manager
 
Posts: 12
Joined: Thu Jul 09, 2015 11:07 am

Wed Nov 20, 2019 10:23 am

Hi,

Thanks for your inquiry.
After an initial test, I didn't find the issue you mentioned. The column height will be adjusted according to the content. Here is my test code:
Code: Select all
            PdfDocument doc = new PdfDocument();
            PdfPageBase page = doc.Pages.Add();
            //create a grid
            PdfGrid grid = new PdfGrid();
            grid.Columns.Add(3);
            float width = page.Canvas.ClientSize.Width / 3;
            //set the width for every column
            for (int j = 0; j < grid.Columns.Count; j++)
            {
                grid.Columns[j].Width = 100;
            }

            for (int i = 0; i < 10; i++)
            {
                grid.Rows.Add();
                grid.Rows[i].Cells[0].Value = "1111 2222 2222 222 dfdf ffff ffff ffff ffff ffff fffffffffffffffffffffffffffffffffff dfdfdfdffffffff";
            }

            grid.Draw(page.Canvas, new PointF(10, 10));
            doc.SaveToFile("result.pdf");

To help us solve your issue accurately, please provide your input file(if any) and the code you were using.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Nov 20, 2019 11:10 am

Hi,

I was able to run your code and it helped me solve the issue.

The problem was that I was not setting the column widths. Once I set column width as per your code text wrap works fine.

You may want to try yourself without setting width and see if you get my original issue.

Thanks

license.manager
 
Posts: 12
Joined: Thu Jul 09, 2015 11:07 am

Thu Nov 21, 2019 2:00 am

Hi,

Thanks for your feedback.
I did see the issue in the last column without setting the column width. But I think you need to set the column width.
If there is any question in the future, welcome to contact us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF