Hello all,

I have a little problem with wrapping. I want to fill whole lines with
underlined spaces and I use fixed cell heights in a table. When I set a
negative padding and setSplitCharacter(...), I can achieve that text
exceeding the table width is just discarded, character by character.
However, the wrapping with spaces seems to work different. I guess that all
spaces are collapsed into white space and then just eliminated. When you run
the following program you can see my problem. I need the spaces to stay
there, because I have to use their underline as a layout element (that's a
requirement I have to meet).

Is there no other way to accomplish this than to change the source code of
iText / subclass a class? If it is like that, where approximately would I
have to make the adaptations? ;-)


Best regards,
Joachim Kanbach


// Illustration code
import com.lowagie.text.pdf.*;
import com.lowagie.text.*;
import java.io.*;

public class Test1 {
    public Test1() {
        Document document = new Document(PageSize.A4, 0, 0, 0, 0);
  try {

            PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("test1.pdf"));
            document.open();

   Font font = new Font(Font.COURIER, 10, Font.UNDERLINE);

   PdfPTable table = new PdfPTable(1);
   table.setTotalWidth(561);

   // first line
   Chunk ch1 = new Chunk("     1", font);
   Chunk ch2 = new Chunk("
2", font);
   ch1.setSplitCharacter(new SplitCharacter() {
    public boolean isSplitCharacter(char c) {
     return true;
    }
   });
   ch2.setSplitCharacter(new SplitCharacter() {
    public boolean isSplitCharacter(char c) {
     return true;
    }
   });

   Phrase ph = new Phrase();
   ph.add(ch1);
   ph.add(ch2);

   PdfPCell cell = new PdfPCell(ph);

   cell.setPadding(0);
   cell.setPaddingTop(-12);
   cell.setPaddingBottom(2);
   cell.setLeading(12, 0);
   cell.setFixedHeight(12);
   cell.setBorder(Rectangle.NO_BORDER);
   table.addCell(cell);

   // second line
   ch1 = new Chunk("     1", font);
   // This time one more space
   ch2 = new Chunk("
2", font);
   ch1.setSplitCharacter(new SplitCharacter() {
    public boolean isSplitCharacter(char c) {
     return true;
    }
   });
   ch2.setSplitCharacter(new SplitCharacter() {
    public boolean isSplitCharacter(char c) {
     return true;
    }
   });

   ph = new Phrase();
   ph.add(ch1);
   ph.add(ch2);

   cell = new PdfPCell(ph);

   cell.setPadding(0);
   cell.setPaddingTop(-12);
   cell.setPaddingBottom(2);
   cell.setLeading(12, 0);
   cell.setFixedHeight(12);
   cell.setBorder(Rectangle.NO_BORDER);
   table.addCell(cell);

   // third line
   // Instead of the whole line being filled by spaces
   // and jump to the next line, text is at beginning of the same line
   ch1 = new Chunk("
1", font);
   ch1.setSplitCharacter(new SplitCharacter() {
    public boolean isSplitCharacter(char c) {
     return true;
    }
   });

   ph = new Phrase();
   ph.add(ch1);

   cell = new PdfPCell(ph);

   cell.setPadding(0);
   cell.setPaddingTop(-12);
   cell.setPaddingBottom(2);
   cell.setLeading(12, 0);
   cell.setFixedHeight(12);
   cell.setBorder(Rectangle.NO_BORDER);
   table.addCell(cell);

   table.writeSelectedRows(0, -1, 17, 800, writer.getDirectContent());
  }
  catch(DocumentException de) {
   System.err.println(de.getMessage());
  }
  catch(IOException ioe) {
   System.err.println(ioe.getMessage());
  }
        document.close();
    }

    public static void main(String[] args) {
        new Test1();
    }
}



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to