Hi,
I have the following problem, if I render text with a ColumnText
object then the output depends where I invoke go(). For example, I get
a different result if I do following steps
1. add paragraph 1 to ColumnText
2. add paragraph 2
3. invoke go()
and
1. add paragraph 1 to ColumnText
2. invoke go()
3. add paragraph 2
4. invoke go()
And I have a special problem with the SpaceAfter property of
paragraphs. I attached the code, which I use to reproduce this
behaviour at the end.
I appreciate every help on what I do wrong.
Thank you, Stephan Michels.
import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public class SpaceAfterTest
{
private static final float COLUMN_WIDTH = 250f;
public static void main(String[] args) throws FileNotFoundException,
DocumentException
{
Document pdfDocument = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(pdfDocument, new
FileOutputStream(test.pdf));
pdfDocument.open();
PdfContentByte cb = writer.getDirectContent();
renderColumn1(pdfDocument, cb);
renderColumn2(pdfDocument, cb);
pdfDocument.close();
}
private static void renderColumn1(Document pdfDocument,
PdfContentByte cb) throws DocumentException
{
cb.rectangle(pdfDocument.left(), pdfDocument.bottom(),
COLUMN_WIDTH, pdfDocument.top() - pdfDocument.bottom());
cb.stroke();
ColumnText ct = new ColumnText(cb);
ct.setUseAscender(true);
ct.setSimpleColumn(pdfDocument.left(), pdfDocument.bottom(),
pdfDocument.left() + COLUMN_WIDTH, pdfDocument.top());
Paragraph paragraph = new Paragraph(test text 1);
paragraph.setSpacingAfter(50);
ct.addElement(paragraph);
ct.addElement(new Paragraph(test text 2));
ct.go();
}
private static void renderColumn2(Document pdfDocument,
PdfContentByte cb) throws DocumentException
{
cb.rectangle(pdfDocument.right() - COLUMN_WIDTH,
pdfDocument.bottom(), COLUMN_WIDTH, pdfDocument.top() -
pdfDocument.bottom());
cb.stroke();
ColumnText ct = new ColumnText(cb);
ct.setUseAscender(true);
ct.setSimpleColumn(pdfDocument.right() - COLUMN_WIDTH,
pdfDocument.bottom(), pdfDocument.right(), pdfDocument.top());
Paragraph paragraph = new Paragraph(test text 1);
paragraph.setSpacingAfter(50);
ct.addElement(paragraph);
ct.go(); // early go, to retrieve the yLine for example
// ct.setYLine(ct.getYLine() + ct.getDescender()); // doesn't help
ct.addElement(new Paragraph(test text 2));
ct.go();
}
}
--
Edna: This is a hobo suit, darling. You can't be seen in this. I
won't allow it.
Bob: Wait, what do you mean? *You* designed it.
Edna: I never look back, darling! It distracts from the now.
The Incredibles (2004)
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/