Hi Paulo,

Below is my test program that creates a pdf document with three columns. For input I used a large plain text file, called /tmp/1.txt.

Regards,
Jacqueline

/*
* TestPdf.java
*
* Created on August 29, 2003, 2:48 PM
*/
import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.*;
/**
*
* @author
*/
public class TestPdf  {

  Font smallFont;
  PdfWriter writer;
  Document document;

  /** Creates a new instance of TestPdf */
  public TestPdf() {
  }

private void run() {

     try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        smallFont = new Font(Font.HELVETICA, 6);

        document = new Document(PageSize.A4, 36, 36, 36, 36);
        // Create a writer that listens to the document
        writer = PdfWriter.getInstance(document, bos);

        document.open();
        makeSmallMessage(readFile("/tmp/1.txt"));
        document.close();
        FileOutputStream fos = new FileOutputStream("/tmp/temp.pdf");
        fos.write(bos.toByteArray());
        fos.close();
        System.out.println("end");


} catch (Exception e) { e.printStackTrace(); } }

//------------------------------------------------------------------------------
/**
* Reads a file in and returns it as a string with \n separating each
* line.
*
* @param fileName the filename to read in.
* @return String contents of the file with \n separating each line
* @throws FileNotFoundException if the file can't be found.
* @throws IOException if there is an IO Exception.
*/
public static String readFile(String fileName)
throws java.io.FileNotFoundException, java.io.IOException {
String returnVal = "";


     BufferedReader in = new BufferedReader(new FileReader(fileName));
     String str;

     while ((str = in.readLine()) != null) {
        returnVal = returnVal + str + "\n";
     }
     in.close();
     return returnVal;
  }

private void makeSmallMessage(String message) throws Exception {

     // Create the columns
     PdfContentByte cb = writer.getDirectContent();
     ColumnText ct = new ColumnText(cb);

     ct.addText(new Phrase(16, message, smallFont));
     ct.setIndent(0);
     ct.setLeading(6);


// Column ones's left and right borders float[] left1 = {30,1050, 30,51}; float[] right1 = {200,1050, 200,81, 170,81, 170,51};

     // Column two's left and right border
     float[] left2 = {205,1050, 205,81};
     float[] right2 = {390,1050, 390,81};

     // Column 3
     float[] left3 = {395,1050, 395,81, 450,81, 450,51};
     float[] right3 = {565,1050, 565,51 };

     int status = 0;
     int column = 0;

     // While there's still more text to print out
     while ((status & ColumnText.NO_MORE_TEXT) == 0) {

        // Set left column points
        if (column == 0) {
          ct.setColumns(left1, right1);
          column = 1;
        }
        // Else set right column points
        else if (column == 1) {
          ct.setColumns(left2, right2);
          column = 2;
        }
        else {
           ct.setColumns(left3, right3);
           column = 0;
        }

        // Print
        status = ct.go();

        // Set top part of columns
        ct.setYLine(800);

        // Set alignment
        ct.setAlignment(Element.ALIGN_JUSTIFIED);
        status = ct.go();

        // Go to a new page
        if ((column == 0) && ((status & ColumnText.NO_MORE_COLUMN) != 0)) {
           document.newPage();
        }
     }
     // Print last bits
     ct.go();

}//makeSmallMessage

  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
     TestPdf tp = new TestPdf();
     tp.run();
  }

}


Re: columntext problems Subject: Re: columntext problems From: "Paulo Soares" <psoares <at> consiste.pt> Date: Fri, 29 Aug 2003 16:01:46 +0100 Newsgroups: gmane.comp.java.lib.itext.general

I would like to see an example.

Best Regards,
Paulo Soares

----- Original Message -----
From: "Jacqueline S" <white_wolf21 <at> hotmail.com>
To: <itext-questions <at> lists.sourceforge.net>
Sent: Friday, August 29, 2003 7:33
Subject: [iText-questions] columntext problems


Hello,

I've encountered some strange behaviour using columnText. I have three

columns, and wish to have the words go around a picture in the bottom centre, such as

..........  ..........  ..........
..........  ..........  ..........
..........  ..........  ..........
..........  ..........  ..........
..........            ..........


What I'm finding is that instead of flowing down 1, then down 2 and down
3, if flows down 1, then down 2 (everything okay), but then the words that should be at the stop of column 3, actually get inserted into column
three's area (but below the text in column 2). Eg, if the numbers indicate the
flow of the words, it looks like this.


1  6  11
2  7  12
3  8  13
4  9  14
5      10

I'm guessing because the area "10" is below area 9, it puts the text
there, instead of filling out the top of column 3 first?

I have example code demonstrating this, iif it will help.  Any help you
can provide will be much appreciated.

Regards
Jacqueline

_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail




-------------------------------------------------------
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