All you need is a p1.setLeading(0, 1) to make it work.
--- Andreas Meyer <[EMAIL PROTECTED]> wrote:
> Here it is :
>
> import java.io.*;
> import java.awt.Color;
> import com.lowagie.text.*;
> import com.lowagie.text.pdf.*;
>
> public class Paragraph_Test
> {
>
> public static void main(String[] args)
> {
>
> Document document = new Document();
>
> try
> {
>
> Font titlefont =
> FontFactory.getFont(FontFactory.HELVETICA, 10,
> Font.BOLD);
> Font subtitlefont =
> FontFactory.getFont(FontFactory.HELVETICA, 8);
> Font locationfont =
> FontFactory.getFont(FontFactory.HELVETICA, 8,
> Font.BOLD, new Color(255, 0, 0));
>
> PdfWriter writer =
> PdfWriter.getInstance(document, new
> FileOutputStream("Paragraph_Test.pdf"));
>
> document.open();
>
> PdfContentByte cb =
> writer.getDirectContent();
>
> ColumnText ct = new ColumnText(cb);
>
> Paragraph p1 = new Paragraph();
>
> Image img =
> Image.getInstance("Event_logo.gif"); // 103px x 44px
>
> p1.add(new Chunk(img, 0 , 0, true));
>
> p1.add(new Chunk("\n"));
>
> p1.add(new Chunk("Event_title\n",
> titlefont));
>
> p1.add(new Chunk("Event_subtitle\n",
> subtitlefont));
>
> p1.add(new Chunk("Event date,
> time and
> location\n", locationfont));
>
> p1.setKeepTogether(true);
>
> p1.setSpacingBefore(img.scaledHeight());
>
> ct.addElement(p1);
>
> float[] links = {20, 160, 300, 440};
> float[] rechts = {140, 280, 420, 560};
>
> int status = 0;
> int column = 0;
> int Seitennummer = 0;
> int idx = 0;
>
> while(status != ColumnText.NO_MORE_TEXT)
> {
> Seitennummer =
> writer.getPageNumber();
>
> ct.setSimpleColumn(links[column],
> 20, rechts[column], 820);
>
> status = ct.go();
>
> if (status ==
> ColumnText.NO_MORE_COLUMN)
> {
> column++;
>
> if (column > 3)
> {
> document.newPage();
> column = 0;
> }
> }
> }
> }
> catch(DocumentException de)
> {
> System.err.println(de.getMessage());
> }
> catch(IOException ioe)
> {
> System.err.println(ioe.getMessage());
> }
>
> document.close();
> }
> }
>
> > Works for me. Post a complete small working
> program.
> >
> > > -----Original Message-----
> > > From:
> [EMAIL PROTECTED]
> > >
> [mailto:[EMAIL PROTECTED]
> On
> > > Behalf Of Andreas Meyer
> > > Sent: Thursday, March 17, 2005 3:59 PM
> > > To: [email protected]
> > > Subject: Re: RE: [iText-questions] text, images,
> background
> > > images and keep together
> > >
> > >
> > > Thank you, but if I only use
> > >
> > > p1.add(new Chunk(img, 0 , 0));
> > >
> > > the first paragraph starts outside the column.
> Is there a
> > > reliable way to
> > > correct this ?
> > >
> > > p1.setSpacingBefore(img.scaledHeight());
> > >
> > > does not work ...
> > >
> > >
> > > > p1.add(new Chunk(img, 0 ,
> -img.scaledHeight())) will drop the image
> > > > below the baseline and autoleading is only
> calculated above the
> > > > baseline.
> > > >
> > > > > -----Original Message-----
> > > > > From:
> [EMAIL PROTECTED]
> > > > >
> [mailto:[EMAIL PROTECTED]
> On
> > > > > Behalf Of Andreas Meyer
> > > > > Sent: Thursday, March 17, 2005 2:34 PM
> > > > > To: [email protected]
> > > > > Subject: Re: RE: [iText-questions] text,
> images, background
> > > > > images and keep together
> > > > >
> > > > > I have experimented with leading as you can
> see, but with no luck:
> > > > >
> > > > > PdfContentByte cb =
> writer.getDirectContent();
> > > > >
> > > > > ColumnText ct = new ColumnText(cb);
> > > > >
> > > > > //ct.setLeading(0, 1);
> > > > >
> > > > > Paragraph p1 = new Paragraph();
> > > > >
> > > > > Image img =
> Image.getInstance("Event_logo.gif");
> > > > >
> > > > > p1.add(new Chunk(img, 0 ,
> -img.scaledHeight())); // Scaled
> > > > > height is about
> > > > > 4*titlefont
> > > > >
> > > > > //p1.add(new Chunk(img, 0 ,
> -img.scaledHeight(), true));
> > > > >
> > > > > p1.add(new Chunk("Event_title\n",
> titlefont));
> > > > >
> > > > > p1.add(new Chunk("Event_subtitle\n",
> subtitlefont));
> > > > >
> > > > > p1.add(new Chunk("Event date, time and
> location\n",
> > > locationfont));
> > > > >
> > > > > p1.setKeepTogether(true); // do not separate
> logo and text !
> > > > >
> > > > > //p1.setLeading(0, 1);
> > > > >
> > > > > ct.addElement(p1);
> > > > >
> > > > >
> > > > > > All that is possible with ColumnText (and
> autoleading
> > > > > works). Post some
> > > > > > snippets of your code and we'll start from
> there.
>
=== message truncated ===
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions