There's a lot of misunderstandings here:

- until you do a document.add(mct) you are just gathering text in mct. A
mct.nextColumn() will do nothing

- onParagraphEnd isn't called in mct

If you need that fine control use a ColumnText.

Paulo 

> -----Original Message-----
> From: raymond moesker [mailto:[EMAIL PROTECTED] 
> Sent: Monday, February 06, 2006 8:24 AM
> To: Paulo Soares
> Subject: RE: [iText-questions] MultiColumnText next column or 
> next page problem
> 
> ok here is some code to reproduce my problem:
> import java.awt.Color;
> import java.io.ByteArrayInputStream;
> import java.io.ByteArrayOutputStream;
> import java.io.File;
> import java.io.FileOutputStream;
> import com.lowagie.text.Document;
> import com.lowagie.text.Element;
> import com.lowagie.text.Font;
> import com.lowagie.text.FontFactory;
> import com.lowagie.text.PageSize;
> import com.lowagie.text.Paragraph;
> import com.lowagie.text.Rectangle;
> import com.lowagie.text.pdf.BaseFont;
> import com.lowagie.text.pdf.MultiColumnText;
> import com.lowagie.text.pdf.PdfEncryptor;
> import com.lowagie.text.pdf.PdfReader;
> import com.lowagie.text.pdf.PdfWriter;
> public class Gen
> {
>  String RGBBackground = "ffffff";
>  public byte[] generatePdf()
>  {
>   byte[] pdfOut = null;
>   PdfReader reader = null;
>   ByteArrayOutputStream baos = new ByteArrayOutputStream();
>   ByteArrayOutputStream finBaos = new ByteArrayOutputStream();
>   try
>   {
>    // Prepare the fonts
>    Document document = new Document(PageSize.A4, 50, 50, 70, 70);
>    float bottom = document.bottomMargin();
>    PdfWriter writer = PdfWriter.getInstance(document, baos);
>    // use PageEvent (extends PdfPageEventHelper) for inserting the
>    // header
>    // and footer
>    MyPageEvent pageEvent = new MyPageEvent();
>    writer.setPageEvent(pageEvent);
>    
>    Rectangle page = document.getPageSize();
>    try
>    {
>     // parse with radix at 16(hex)
>     int rgb = Integer.parseInt(RGBBackground, 16);
>     page.setBackgroundColor(new java.awt.Color(rgb));
>    }
>    catch (NumberFormatException nfe)
>    {
>     // fallback to white
>     page.setBackgroundColor(java.awt.Color.WHITE);
>    }
>    document.open();
> 
>    // create the subheader
>    document.add(makeParagraph(" ", 10, Element.ALIGN_LEFT, 
> Font.NORMAL, false, Color.BLACK));
>    document.add(makeParagraph("head", 10, Element.ALIGN_LEFT, 
> Font.BOLD, false, Color.BLACK));
>    document.add(makeParagraph("\n\n", 10, Element.ALIGN_LEFT, 
> Font.NORMAL, false, Color.BLACK));
>    // set up 2 even columns with 10pt space between
>    MultiColumnText mct = new MultiColumnText();
>    mct.addRegularColumns(document.left(), document.right(), 10f, 2);
>    // Write body
>    int size=15;
>    for (int i = 0; i < size; i++)
>    {
>     mct.addElement(new Paragraph("GALLIA est omnis divisa in 
> partes,GALLIA est omnis divisa in partes,GALLIA est omnis 
> divisa in partes ,GALLIA est omnis divisa in partes ,GALLIA 
> est omnis divisa in partes ,GALLIA est omnis divisa in partes 
> ,GALLIA est omnis divisa in partes ,GALLIA est omnis divisa 
> in partes ,GALLIA est omnis divisa in partes  "));
>     if (i < size - 1)
>     {
>      // Phrase p = new Phrase("\n\ncccc", fontHelvetica10);
>      Element p = 
> makeParagraph("\n______________________________________\n\n", 
> 8, Element.ALIGN_CENTER,
>        Font.NORMAL, false, Color.GRAY);
>      
>      mct.addElement(p);
>      
>       mct.addElement(new Paragraph("GALLIA est omnis divisa 
> in partes "));
>      if(bottom-pageEvent.pPosition<30)
>      {
>        mct.nextColumn();
>      }
>      
>     }
>    }
>    
>    document.add(mct);
>    document.close();
>    reader = new PdfReader(baos.toByteArray());
>    PdfEncryptor.encrypt(reader, finBaos, null, null, 
> PdfWriter.AllowPrinting, false);
>    pdfOut = finBaos.toByteArray();
>    baos.flush();
>    finBaos.flush();
>    baos.close();
>    finBaos.close();
>   }
>   catch (Exception e)
>   {
>    System.out.print(e);
>   }
>   return pdfOut;
>  }
>  public Element makeParagraph(String text, int size, int 
> alignment, int type, boolean fixed, Color r)
>  {
>   Font font = null;
>   BaseFont fixedfont = null;
>   if (!fixed)
>   {
>    font = FontFactory.getFont("Helvetica", size, type, r);
>   }
>   else
>   {
>    try
>    {
>     fixedfont = BaseFont.createFont(BaseFont.COURIER, 
> BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
>    }
>    catch (Exception e)
>    {
>     e.printStackTrace();
>    }
>    font = new Font(fixedfont, size, type, r);
>   }
>   Paragraph p = new Paragraph(text, font);
>   p.setAlignment(alignment);
>   p.setLeading(font.size() * 1.2f);
>   
>   return p;
>  }
>  public static void main(String[] args)
>   {
>   Gen pg = new Gen();
>   byte[] b = pg.generatePdf();
>  
>   ByteArrayInputStream ba = new ByteArrayInputStream(b);
>   FileOutputStream fos = null;
>   try
>   {
>   fos = new FileOutputStream(new File("c:/test.pdf"));
>   fos.write(b);
>   fos.flush();
>   fos.close();
>   ba.close();
>   }
>   catch (Exception e)
>   {
>   System.out.println(e);
>   }
>  
>   System.out.println("ready");
>   }
> }
>  
> //////////////////////////////////////////////////////
>  
> import com.lowagie.text.Document;
> import com.lowagie.text.pdf.PdfPageEventHelper;
> import com.lowagie.text.pdf.PdfWriter;
> public class MyPageEvent extends PdfPageEventHelper
> {
>  public float pPosition;
>  public MyPageEvent()
>  {
>  }
>  public void onParagraphEnd(PdfWriter writer, Document 
> document, float paragraphPosition)
>  {
>   pPosition = paragraphPosition;
>   System.out.println("trigger");
>  }
> }
>  
> ////////////////////////////////
>  
> as you can see it prints out 3 times "trigger" at document level.
>  
> gr ray
> 
> Paulo Soares <[EMAIL PROTECTED]> wrote:
> 
>       Some code is required to reproduce the problem. 
>       
>       > -----Original Message-----
>       > From: [EMAIL PROTECTED] 
>       > [mailto:[EMAIL PROTECTED] On 
>       > Behalf Of raymond moesker
>       > Sent: Thursday, February 02, 2006 3:58 PM
>       > To: itext-questions@lists.sourceforge.net
>       > Subject: [iText-questions] MultiColumnText next column or 
>       > next page problem
>       > 
>       > Some background info: 
>       > I'm trying to add articles to a PDF file using the 
>       > MultiColumnText class. This works fine.
>       > My problem is when an article starts at the almost end of a 
>       > column it has to move to the next column or next page if it 
>       > is the second column.
>       > 
>       > What I do:
>       > I'm opening a Document.(I'm using a PageEvent for adding the 
>       > footer and header) Then I create a MultiColumnText. This 
>       > MultiColumnText gets filled with articles and after it's 
>       > filled it's added to the Document.
>       > 
>       > My problems:
>       > 1.
>       > When I'm using the mct.nextColumn() function within the 
>       > MultiColumnText it only works for the first page.
>       > 
>       > 2.
>       > My first thought was to use a onParagraphEnd(PageEvent) to 
>       > calculate the end of a Paragraph in a MultiColumnText. This 
>       > only seems to work at the Document level.
>       > 
>       > 
>       > Does someone know a solution for my problem?(when a article 
>       > starts at the almost end of a column it has to move to the 
>       > next column or next page if it is the second column.)
>       > 
>       > Thanks Ray
>       > 
>       > ________________________________
>       > 
>       > Yahoo! Autos 
>       > ylc=X3oDMTEzcGlrdGY5BF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDMW
>       > F1dG9z/*http://autos.yahoo.com/index.html> . Looking for a 
>       > sweet ride? Get pricing, reviews, & more on new and used cars.
>       > 
>       
>       
>       -------------------------------------------------------
>       This SF.net email is sponsored by: Splunk Inc. Do you 
> grep through log files
>       for problems? Stop! Download the new AJAX search engine 
> that makes
>       searching your log files as easy as surfing the web. 
> DOWNLOAD SPLUNK!
>       
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
>       _______________________________________________
>       iText-questions mailing list
>       iText-questions@lists.sourceforge.net
>       https://lists.sourceforge.net/lists/listinfo/itext-questions
>       
> 
> 
> ________________________________
> 
> Brings words and photos together (easily) with
> PhotoMail 
> <http://us.rd.yahoo.com/mail_us/taglines/PMDEF3/*http://photom
> ail.mail.yahoo.com> - it's free and works with Yahoo! Mail.
> 


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to