Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » iText »

[iText-questions] Character Spacing and Word Spacing in Column Text

Tobias Seckinger

2007-06-13



Hi all,

I use iText 2.0.4 and it's great! Uh, and sorry for this bad english... But
one thing I do not understand. The example code at the end of this mail
demonstrate my problem. In my program I use the class ColumnText to write
text with different borders. Furthermore some text have different character
and word spacings, but the result looks not fine. Either the page break
doesn't work correctly or nothing is happens.

Someone has an idea who this works?

Greets

Tobias
-------------------------------------
Example code:

public class iTextSpacingTest {

 public static void main(String[] args) {
   iTextSpacingTest test = new iTextSpacingTest();
   test.test1();
 }
 
 public iTextSpacingTest() {
 }
 
 public void test1() {
   try {
     // Step 1
     Document document = new Document();
     document.setPageSize(PageSize.A4);
     // Step 2      
     PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream("test1.pdf"));
     // Step 3
     document.open();
     // Step 4
     PdfContentByte cb = writer.getDirectContent();
     // Step 5      
     document.add(new Paragraph("Test"));
     
     // Borders, normally much more complex
     float[] leftBorder = {0,0,0,PageSize.A4.height()};
     float[] rightBorder =
{PageSize.A4.width(),0,PageSize.A4.width(),PageSize.A4.height()};
     
     ColumnText ct = new ColumnText(cb);
     
     ct.setColumns(leftBorder, rightBorder);
     
     ct.setYLine(PageSize.A4.height() - 100f);
     
     ct.setSpaceCharRatio(10f);      
     Chunk chunk1 = new Chunk("Text with Letter-Spacing!
Text with Letter-Spacing! Text with Letter-Spacing! Text with
Letter-Spacing! Text with Letter-Spacing! Text with Letter-Spacing! Text
with Letter-Spacing! Text with Letter-Spacing! Text with Letter-Spacing!
Text with Letter-Spacing! Text with Letter-Spacing! Text with
Letter-Spacing! Text with Letter-Spacing! Text with Letter-Spacing! Text
with Letter-Spacing! Text with Letter-Spacing! Text with Letter-Spacing!
Text with Letter-Spacing! Text with Letter-Spacing! Text with
Letter-Spacing! Text with Letter-Spacing! Text with Letter-Spacing! Text
with Letter-Spacing! Text with Letter-Spacing! Text with Letter-Spacing!
Text with Letter-Spacing! Text with Letter-Spacing! Text with
Letter-Spacing! Text with Letter-Spacing! Text with Letter-Spacing! Text
with Letter-Spacing! Text with Letter-Spacing! ");

     Phrase phrase1 = new Phrase(chunk1);

     ct.addText(phrase1);
     
     ct.setSpaceCharRatio(0f);      
     Chunk chunk2 = new Chunk("Text without
Letter-Spacing! Text without Letter-Spacing! Text without Letter-Spacing!
Text without Letter-Spacing! Text without Letter-Spacing! Text without
Letter-Spacing! Text without Letter-Spacing! Text without Letter-Spacing!
Text without Letter-Spacing! Text without Letter-Spacing! Text without
Letter-Spacing! Text without Letter-Spacing! Text without Letter-Spacing!
Text without Letter-Spacing! Text without Letter-Spacing! Text without
Letter-Spacing! Text without Letter-Spacing! Text without Letter-Spacing!
Text without Letter-Spacing! Text without Letter-Spacing! Text without
Letter-Spacing! Text without Letter-Spacing! Text without Letter-Spacing!
Text without Letter-Spacing! Text without Letter-Spacing! Text without
Letter-Spacing! Text without Letter-Spacing! Text without Letter-Spacing!
Text without Letter-Spacing! ");

     Phrase phrase2 = new Phrase(chunk2);

     ct.addText(phrase2);
     
     ct.go();
     
     cb.setCharacterSpacing(10f);
     Chunk chunk3 = new Chunk("Text with letter-spacing,
but the line break will not be correct... Text with letter-spacing, but the
line break will not be correct... Text with letter-spacing, but the line
break will not be correct... Text with letter-spacing, but the line break
will not be correct... ");      
     Phrase phrase3 = new Phrase(chunk3);

     ct.addText(phrase3);
     
     ct.go();
           
     document.close();  
   }
   catch (Exception e) {
     e.printStackTrace();
   }
   System.out.println("finish");
     
 }
 
}
 


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
iText-questions@(protected)
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/
©2008 junlu.com - Jax Systems, LLC, U.S.A.