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.
> > > > > 
> > > > > > -----Original Message-----
> > > > > > From: itext-questions-admin <at> lists.sourceforge.net 
> > > > > > [mailto:itext-questions-admin <at> lists.sourceforge.net] On 
> > > > > > Behalf Of Andreas Meyer
> > > > > > Sent: Thursday, March 17, 2005 5:23 AM
> > > > > > To: itext-questions <at> lists.sourceforge.net
> > > > > > Subject: [iText-questions] text, images, background images 
> > > > > > and keep together
> > > > > > 
> > > > > > hi all,
> > > > > > I am new to iText and need to combine text with images or 
> > > > > > background images in
> > > > > > columns, preferably with automatic keep together of certain 
> > > > > > parts (text/text,
> > > > > > text/image). Can someone please recommend me, which 
> > > > > > combination of objects is
> > > > > > best suitable for this ? I have already tried to solve the 
> > > > > > problem with
> > > > > > ColumnText/Paragraph, but I could not get autoleading to work.
> > > > > > 
> > > > > > Thanks in advance,
> > > > > > Andreas Meyer

Attachment: Paragraph_Test.pdf
Description: Adobe PDF document

Reply via email to