/*
 * $Id: Chap1007.java,v 1.1 2001/08/01 10:27:01 blowagie Exp $
 * $Name:  $
 *
 * This code is free software. It may only be copied or modified
 * if you include the following copyright notice:
 *
 * --> Copyright 2001 by Bruno Lowagie <--
 *
 * This code is part of the 'iText Tutorial'.
 * You can find the complete tutorial at the following address:
 * http://www.lowagie.com/iText/tutorial/
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * ir-arch Bruno Lowagie,
 * Adolf Baeyensstraat 121
 * 9040 Sint-Amandsberg
 * BELGIUM
 * tel. +32 (0)9 228.10.97
 * bruno@lowagie.com
 */

import java.io.FileOutputStream;
import java.io.IOException;
import java.awt.Color;

import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.ColumnText;
import com.lowagie.text.pdf.PdfContentByte;

public class Chap1007new {

	public static void main(String[] args) {

		System.out.println("Chapter 10 example 7: Columns");

		// step 1: creation of a document-object
		Document document = new Document();

		try {

			// step 2:
			// we create a writer that listens to the document
			// and directs a PDF-stream to a file
			PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Chap1007new.pdf"));

			// step 3: we open the document
			document.open();

			// step 4:
            BaseFont bf = BaseFont.createFont("Helvetica", "Cp1252", false);
            Font font = new Font(bf, 11, Font.NORMAL);
                        
            // we grab the ContentByte and do some stuff with it
            PdfContentByte cb = writer.getDirectContent();
            ColumnText ct = new ColumnText(cb);   
            float[] left = {20, 210, 400};
            float[] right = {190, 380, 570};
            ct.addText(new Phrase("First Middle Last How does a long one affect the code?\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last How does a long one affect the code?\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last How does a long one affect the code?\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last How does a long one affect the code?\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last How does a long one affect the code?\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last How does a long one affect the code?\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last How does a long one affect the code?\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            ct.addText(new Phrase("First Middle Last How does a long one affect the code?\nGroup\nStreet\nCity/AB  Postal\n", new Font(Font.HELVETICA, 12)));            
            int status = 0;
            int column = 0;
            while((status & ColumnText.NO_MORE_TEXT) == 0) {
                System.out.println("page " + writer.getPageNumber() + " column " + column);       
                ct.setSimpleColumn(left[column], 20, right[column], 810, 16, Element.ALIGN_JUSTIFIED); //llx lly urx ury leading align
                status = ct.go();
                if ((status & ColumnText.NO_MORE_COLUMN) != 0) {
                    column++;
                    if (column > 2) {
                        document.newPage();
                        column = 0;
                    }
                }
            } 
		}
		catch(DocumentException de) {
			System.err.println(de.getMessage());
		}
		catch(IOException ioe) {
			System.err.println(ioe.getMessage());
		}

		// step 5: we close the document
		document.close();
	}
}

