Word Wrapping

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v7)  /  Re: Word Wrapping

DynamicPDF CoreSuite for .NET (v7) Forum

 Dec 09 2012 2:11 PM
Hello,

Is there a way to disable wrapping of text within a cell? I want the text to clip but I can't seem to find any way to do that.

Thanks
 Dec 10 2012 5:52 AM
Posted by a ceTe Software moderator
Hello,

You can avoid text wrapping in the cell by adding the contents using Label page element. You will need build a Label class object and set the Label width as column's width. Also make sure that you are setting the desired height for the label so that it can fit only one line of text and then add this label object to the cell of the Table2. Below is the sample code for it.

          // Create a PDF Document
            Document document = new Document();
            // Create a Page and add it to the document
            Page page = new Page();
            document.Pages.Add(page);
            // Create a table
            Table2 table = new Table2(0, 0, 600, 600);
            //Add columns to the table
            Column2 column1 = table.Columns.Add(150);
            // Add rows to the table and add cells to the rows
            Row2 row1 = table.Rows.Add();
            row1.Cells.Add("Header 1");
            Row2 row2 = table.Rows.Add();
            //Build Label page element by setting width as column's width.
            Label label = new Label("This is to test of text wrapping", 0, 0, 150, 20,Font.Helvetica,12);
            //Add the label to the cell of the Table2.
            Cell2 cell1 = row2.Cells.Add(label);
            // Add the table to the page
            page.Elements.Add(table);
            // Save the PDF
            document.Draw(@"C:\MyDocument.pdf");

If the above suggestions do not meet your requirements then please send over more details about your requirements to our support team so that they can look into it further.

Thanks,
ceTe Software Support Team.
 Dec 10 2012 6:21 AM
Wow, that's pretty complicated just to turn off word wrapping. Replacing the text in each one of my cells with individual labels represents quite a bit of effort. You can set the text alignment within the cell. It seems like you should also be able to set the text to clip.
 Dec 10 2012 1:14 PM
Posted by a ceTe Software moderator
Hello,

At this time, the only way to disable word wrapping in the table cell is to use a Label page element as suggested above.

Thanks,
ceTe Software Support Team.
 Jan 21 2016 1:16 PM
Is there any update to this?
 Jan 22 2016 9:23 AM
Posted by a ceTe Software moderator
Hello,

Using Label page element as suggested above is the only way to truncate text or disable word wrapping in a table cell.

Thanks,
ceTe Software Support Team.
 Sep 24 2018 5:45 PM
Hi,

I can make the Label element approach sort of work, but not entirely. How can I figure out the proper height for the no-wrap Label to make it match its neighboring yes-wrap cells? E.g. if I use a 10pt font for cells {A, B, C}, where A shouldn't wrap, but B and C should, what height should I use for the Label for A? The issue is that the cells are not vertically aligned.

Thanks,

Jesse Perrin
 Sep 26 2018 10:08 AM
Posted by a ceTe Software moderator
Hello Jesse,

The DynamicPDF API sets the height of the row to the height of the largest cell in that row. Also the DynamicPDF API sets minimum height for the Label page element to display at least one line of text.  If the specified height for the Label is more than that of minimum height then API will preserve the specified height. In the code sample below, we are setting Label height to zero value, the DynamicPDF API calculates the default height to display a line of text and sets it to Label dynamically.
 
           // Create a PDF Document
            Document document = new Document();
            // Create a Page and add it to the document
            Page page = new Page();
            document.Pages.Add(page);
            // Create a table
            Table2 table = new Table2(0, 0, 600, 600);
            //Add columns to the table
            Column2 column1 = table.Columns.Add(150);
            Column2 column2 = table.Columns.Add(150);
            Column2 column3 = table.Columns.Add(150);
            // Add rows to the table and add cells to the rows
            Row2 row1 = table.Rows.Add();
            row1.Cells.Add("Header 1");
            row1.Cells.Add("Header 2");
            row1.Cells.Add("Header 3");
            Row2 row2 = table.Rows.Add();
 
            float fontSize = 12;
            Font fontObj = Font.Helvetica;
            string text = "This is to test of text wrapping";
            Label label = new Label(text, 0, 0, 150, 0, fontObj, fontSize);
            label.VAlign = VAlign.Center;
            //Add the label to the cell of the Table2.
            Cell2 cellA = row2.Cells.Add(label);
            cellA.VAlign = VAlign.Center;
            cellA.Align = TextAlign.Center;
 
            string text1 = "This is text in cell where in the text is wrapped to new line as per the width of the cell/column";
            Cell2 cellB = row2.Cells.Add(text1);
            Cell2 cellC = row2.Cells.Add(text1);
             // Add the table to the page
            page.Elements.Add(table);
            // Save the PDF
            document.Draw(@"C:\Temp\MyDocument.pdf");
 
If you would like to calculate the height of the text then you can achieve it using Font object. Below is the code sample.
 
            float fontSize = 12;
            Font fontObj = Font.Helvetica;
            string text2 = "This is to test of text wrapping";
            float height2 = fontObj.GetBaseLine(fontSize, fontObj.GetDefaultLeading(fontSize)) + fontObj.GetAscender(fontSize) + fontObj.GetDescender(fontSize);
            Label label2 = new Label(text2, 0, 200, 150, height2, fontObj, fontSize);
            label2.VAlign = VAlign.Center;
 
Thanks,
ceTe Software Support Team.
 Sep 26 2018 4:16 PM
That helps. Thanks! I think it resolves our issue.
 Nov 29 2021 7:59 PM
Is there a way to force the label to chop a word rather than clipping at a word break?  The problem with clipping at a word break is that can make the user think that the underlying data is truncated rather than it being a display length limitation.

For example, if I'm trying to display "Microsoft Windows",   If that gets chopped like this:  "Microsoft Wind", then it's clear that the data is chopped.  Chopping at the word break causes it to display like this "Microsoft         "...meaning there is a bunch of space.  That space makes people think it's displaying the entire entry when it's not. 

I suspect what's going on is that word wrapping is pushing "Windows" to the next line which is being clipped at the bottom edge of the control.  It should be possible to disable word wrapping.  That should cause it to clip at the right edge of the control (or left edge if right aligned).  So I think being able to disable word wrapping in the label would solve the problem, but I don't see any way to do that.

Thanks



 Nov 30 2021 1:16 PM
Posted by a ceTe Software moderator
Hi,

DynamicPDF Core Suite wraps words based on space character between the words.

There is no option available to disable word wrapping.

Thanks,
ceTe Software Support Team

All times are US Eastern Standard time. The time now is 1:20 AM.