Martin Spek wrote:

Bruno

I'm testing at home.
I will send you the tests and the results this evening.

In attachment you'll find some tests of my own.
First I draw some lines to visualize the different columns,
then I add the 'Quick brown fox' sentence in text mode
four times: justified, centered, aligned to the left and aligned
to the right.
Then I add the sentence in composite mode.
In composite mode, the alignment and leading of the column
is ignored in favor of the alignment and leading of the elements
inside the ColumnText object.
The line were drawn in gray, and as you can see the alignment
is done very accurately.
br,
Bruno

Attachment: columntext.pdf
Description: Adobe PDF document

package test;

import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.ColumnText;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

public class ColumnTextExamples {

	public static void main(String[] args) {
		Document document = new Document(PageSize.A4);
		try {
			// step 2:
			// we create a writer
			PdfWriter writer = PdfWriter.getInstance(
					// that listens to the document
					document,
					// and directs a PDF-stream to a file
					new FileOutputStream("columntext.pdf"));
			// step 3: we open the document
			document.open();
			// step 4: we add a table to the document
			PdfContentByte cb = writer.getDirectContent();
			cb.setRGBColorStroke(0xC0, 0xC0, 0xC0);
			cb.moveTo(40, 36);
			cb.lineTo(40, PageSize.A4.height() - 36);
			cb.moveTo(120, 36);
			cb.lineTo(120, PageSize.A4.height() - 36);
			cb.moveTo(160, 36);
			cb.lineTo(160, PageSize.A4.height() - 36);
			cb.moveTo(240, 36);
			cb.lineTo(240, PageSize.A4.height() - 36);
			cb.moveTo(120, 36);
			cb.lineTo(120, PageSize.A4.height() - 36);
			cb.moveTo(280, 36);
			cb.lineTo(280, PageSize.A4.height() - 36);
			cb.moveTo(360, 36);
			cb.lineTo(360, PageSize.A4.height() - 36);
			cb.moveTo(400, 36);
			cb.lineTo(400, PageSize.A4.height() - 36);
			cb.moveTo(480, 36);
			cb.lineTo(480, PageSize.A4.height() - 36);
			cb.stroke();
			
			ColumnText ct = new ColumnText(cb);
			
			// text mode: chunks and phrases only
			
			ct.addText(new Phrase("Quick brown fox jumps over the lazy dog"));
			ct.setSimpleColumn(40, 36, 120, PageSize.A4.height() - 36, 18, Element.ALIGN_JUSTIFIED);
			ct.go();

			ct.addText(new Phrase("Quick brown fox jumps over the lazy dog"));
			ct.setSimpleColumn(160, 36, 240, PageSize.A4.height() - 36, 18, Element.ALIGN_CENTER);
			ct.go();
			
			ct.addText(new Phrase("Quick brown fox jumps over the lazy dog"));
			ct.setSimpleColumn(280, 36, 360, PageSize.A4.height() - 36, 18, Element.ALIGN_LEFT);
			ct.go();

			ct.addText(new Phrase("Quick brown fox jumps over the lazy dog"));
			ct.setSimpleColumn(400, 36, 480, PageSize.A4.height() - 36, 18, Element.ALIGN_RIGHT);
			ct.go();
			
			// composite mode: any object
			
			Paragraph p = new Paragraph("Justified: Quick brown fox jumps over the lazy dog");
			p.setAlignment(Element.ALIGN_JUSTIFIED);
			ct.addElement(p);
			p = new Paragraph("Centered: Quick brown fox jumps over the lazy dog");
			p.setAlignment(Element.ALIGN_CENTER);
			ct.addElement(p);
			p = new Paragraph("Left: Quick brown fox jumps over the lazy dog");
			p.setAlignment(Element.ALIGN_LEFT);
			ct.addElement(p);
			p = new Paragraph("Right: Quick brown fox jumps over the lazy dog");
			p.setAlignment(Element.ALIGN_RIGHT);
			ct.addElement(p);
			ct.setSimpleColumn(40, 36, 120, PageSize.A4.height() - 144);
			ct.go();
		} catch (DocumentException de) {
			System.err.println(de.getMessage());
		} catch (IOException ioe) {
			System.err.println(ioe.getMessage());
		}

		// step 5: we close the document
		document.close();
	}
}
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to