views:

25

answers:

0

I'm using iTextSharp in C# to create a pdf with numbers of cells which are containing both image and texts.

            Document document = new Document(rect, marginLeft, marginRight, marginTop, marginBottom);

    Table aTable = new Table(tableColumns);

                   foreach (TitleAndCode s in samples)
            {
                        // Create new barcode
                Image imageCode128 = GetImageCode128(s.code, barHeight, cb);

                // Create a new cell to host the barcode image
                Cell cell = new Cell();
                cell.SetHorizontalAlignment("Center");// "Left", "Center", "Justify", and "Right"
                cell.BorderWidth = 0;
                cell.Add(imageCode128);

                // Also add in a line of text to display the sample name (title
                Chunk chunkTitle = new Chunk(s.title, FontFactory.GetFont("Arial", fontSize, Font.NORMAL,
                                                                          new Color(25, 25, 25)));


                cell.Add(chunkTitle);
                aTable.AddCell(cell);

                        }

            // Add the completed table to the Document and close it.
            document.Add(aTable);

            document.Close();

The problem is when the chunkTitle is longer than the width of the cell, it will automatically wrap making the heigt of the cell bigger than I expected. So what I want is to make the chunkTitle in one line even if cut it partly. Since the cell contains both image and text, the attribute "Nowrap" of the cell can't be used. And if I make the image and text in different cells, when the table sets to several columns, the text will not be right under the image... Is there any method to cut the text if it is too long?