I'm using iTextSharp and I'm trying to use PdfPCell cells that do not wrap.
In my PdfPTable, I'm trying to prevent the cells in the first column from
wrapping.  I've tried using setNoWrap but there are 2 issues.  In Java,
PdfPCell.setNoWrap(true) works, but the Phrase inside the cell overwrites
the adjacent cell.  In C#, PdfPCell.NoWrap = true has no effect.  
 
I've modified PdfPRows.cs as well as PDfPTable.cs to correspond to the
latest Java iText version.  The C# version had different PdfPRows.writeCells
and PDfPTable.writeSelectedRows methods.  This does not work.

Is there a different way of preventing the PdfPCell contents from wrapping?
Is it possible to prevent just the first column from wrapping even if there
are other columns in the same row that wrap?

I've attached the PDF outputs of both C# and Java.

// C# Version
using System;
using System.IO;
using System.Collections;
using System.Diagnostics;
using System.Threading;

using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;

public class MyClass
{
        public static void Main()
        {
                String f = "C:\\TEMP\\_nowrap.cs.pdf";
                Document d = new Document(PageSize.LETTER);
                PdfWriter w = PdfWriter.getInstance(d, new FileStream(f,
FileMode.Create));
                
                d.Open();
                PdfPTable t = new PdfPTable(10);
                for (int i = 0; i < 20; i++)
                {
                        PdfPCell c; 
                        c = new PdfPCell(new Phrase(new Chunk("Chunk Wrap" +
i)));
                        if (i % 10 == 0) 
                        {
                                c.NoWrap = true;
                        }
                        t.addCell(c);
                }
                d.Add(t);
                d.Close();
                
                
                Process p = new Process();
                try {
                        p.StartInfo.FileName = f;
                        p.StartInfo.CreateNoWindow = true;
                        p.Start();
                } catch (Exception e) {
                        Console.WriteLine(e.Message);
                }
        }       
}
 
// Java version
import java.io.FileOutputStream;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

public class Test {
        public static void main(String[] args) {
                String f = "C:/temp/_nowrap.java.pdf";
                Document d = new Document(PageSize.LETTER);
                try {
                        PdfWriter w = PdfWriter.getInstance(d, new
FileOutputStream(f));   
                } catch (Exception e) {
                        // TODO: handle exception
                }
                
                d.open();
                PdfPTable t = new PdfPTable(10);
                for (int i = 0; i < 20; i++) {
                        PdfPCell c;
                        c = new PdfPCell(new Phrase(new Chunk("Chunk Wrap" +
i)));
                        if (i % 10 == 0) {
                                c.setNoWrap(true);
                        }
                        t.addCell(c);
                }
                try {
                        d.add(t);       
                } catch (Exception e) {
                        // TODO: handle exception
                }               
                d.close();              
        }
}


Attachment: _nowrap.cs.pdf
Description: Adobe PDF document

Attachment: _nowrap.java.pdf
Description: Adobe PDF document

Reply via email to