Hi,

I have been trying to create a PDF document using the
iText API. I am encountering the following problem -->

1. I am using ColumnText to split the contents into
two columns per page (I am using the method -->
ct.go(), to write, where ct is the columntext object).
2. The content is a mix of text and image. 
3. The problem I have is when the writer writes the
image as the first item on a page , it does not
position the image by taking its height into account.
Hence, the image sometimes ends up interfering with
the headers in the page.

 Is there any way I can control the position of the
image, when it is the first item to be written to a
page?  

Thanks!

The code I am using -->

                Font headerPortFont =
FontFactory.getFont(FontFactory.TIMES_BOLD, 12,
Font.NORMAL);
                Font titlePortFont =
FontFactory.getFont(FontFactory.TIMES_ROMAN, 12,
Font.NORMAL);
                titlePortFont.setColor(Color.blue);     
                Font textPortFont =
FontFactory.getFont(FontFactory.TIMES_ROMAN, 10,
Font.NORMAL);
                
                PdfContentByte cb = docWriter.getDirectContent();
                ShorexNewBean shorexBean = new ShorexNewBean();
        ShorexNew[] shorexSet =
shorexBean.getShorexNews(portId); //Database call

                try{
                
                        ColumnText ct = new ColumnText(cb);
            //float[] right = {70, 320};
            //float[] left = {300, 550};

                        if(shorexSet != null){
                    ArrayList list = new ArrayList();
                                for(int i=0; i< shorexSet.length; i++){
                                
                        String shorexTitle =
shorexSet[i].getShorexTitle();                                          
                        String shorexId =
shorexSet[i].getShorexId();
                
                                        String description =
shorexSet[i].getLongDescription() ==
null?"":shorexSet[i].getLongDescription();
                                        String duration = shorexSet[i].getDuration() ==
null?"":shorexSet[i].getDuration();
                                        String notes = shorexSet[i].getNotes() ==
null?"":shorexSet[i].getNotes();

                                        String startDate = shorexSet[i].getStartDate();
                                        String endDate = shorexSet[i].getEndDate();
                                        String priceAdult = 
shorexSet[i].getPriceAdult();
                                        String priceChild = 
shorexSet[i].getPriceChild();

                                        //Create an image...
                                        URL url = new URL("icon_moderate.gif");
                                        Image image = Image.getInstance(url);
                                        image.setAlignment(Image.TEXTWRAP);
                                        Chunk chunk = new Chunk(image, (float)10.0,
(float)-15.0);

                                        URL url1 = new URL("shorex_sub.jpg");
                                        Image image1 = Image.getInstance(url1);
                                        image1.setAlignment(Image.ALIGN_TOP);
                                        Chunk chunk1 = new Chunk(image1, (float)0.0,
(float)0.0, true);

                

                                        Phrase title = new Phrase(i + 1 + ": " +
shorexTitle + "\n\n", titlePortFont);
                                        list.add(title);
                                        Phrase descriptionTitle= new Phrase("Shorex
Description : " + "\n" , headerPortFont);
                                        //list.add(descriptionTitle);
                                        
                                        Phrase testPhrase = new Phrase();
                                        Phrase descriptionPhrase = new 
Phrase(description
+ "\n\n\n\n\n\n\n\n\n\n\n\n", textPortFont);
                                        testPhrase.add(chunk1);
                                        testPhrase.add(new Phrase("\n\n"));
                                        //testPhrase.add(descriptionPhrase);
                                        //list.add(descriptionPhrase);
                                        //list.add(testPhrase);

                                        Paragraph p = new Paragraph();
                                        p.add(descriptionTitle);
                                        p.add(descriptionPhrase);
                                        p.add(testPhrase);
                                        p.setKeepTogether(true);
                                        list.add(p);
                                        
                                        Phrase  durationTitle = new 
Phrase("Duration\n",
headerPortFont);
                                        Phrase durationPhrase = new Phrase(duration +
"\n\n", textPortFont);
                                        list.add(durationTitle);
                                        list.add(durationPhrase);
                                                                                
                                        Phrase  notesTitle = new Phrase("Special Notes
\n", headerPortFont);
                                        Phrase  notesPhrase = new Phrase(notes + 
"\n\n",
textPortFont);
                                        list.add(notesTitle);
                                        list.add(notesPhrase);

                                        //added on 12/09/2003
                                        Phrase activityLevel = new Phrase("Activity 
Level
\n", headerPortFont);
                                        Phrase icon = new Phrase(chunk);
                                        icon.add(new Phrase("\n\n"));
                                        list.add(activityLevel);
                                        list.add(icon);

                                        Phrase validDateTitle = new Phrase("Valid 
Dates:
\n", headerPortFont);
                                        Phrase validDatePhrase = new Phrase(startDate 
+ "
To " + endDate + "\n\n", textPortFont);

                                        Phrase priceAdultTitle = new Phrase("Price 
Adult:
", headerPortFont);
                                        Phrase priceAdultPhrase = new 
Phrase(priceAdult +
"\n\n", textPortFont);
                                        
                                        Phrase priceChildTitle = new Phrase("Price 
Adult:
", headerPortFont);
                                        Phrase priceChildPhrase = new 
Phrase(priceChild +
"\n\n", textPortFont);

                                        list.add(validDateTitle);
                                        list.add(validDatePhrase);
                                        list.add(priceAdultTitle);
                                        list.add(priceAdultPhrase);
                                        list.add(priceChildTitle);
                                        list.add(priceChildPhrase);

                    Phrase newLine = new
Phrase("\n\n\n");
                                        list.add(newLine);
            

                                }//end for

                                Iterator iter = list.iterator();
                                while(iter.hasNext()){
                                        Phrase text = (Phrase)(iter.next());
                                        ct.addText(text);
                                }
                                            
                    float[] left = {50, 370};
                    float[] right = {356, 750};

                    int status = 0;
                    int column = 0;

            //    System.out.println("page " +
writer.getPageNumber() + " column " + column);
                    while((status & ColumnText.NO_MORE_TEXT)
== 0) {
                                ct.setSimpleColumn(left[column], 60,
right[column], 500, 10, Element.ALIGN_JUSTIFIED);                               
                        status = ct.go();
                        if ((status &
ColumnText.NO_MORE_COLUMN) != 0) {
                            column++;
                            if (column > 1) {
                                //System.out.println("Next Page
- " + column);
                                doc.newPage();
                                column = 0;
                            }

                        } //end if
                    }//end while
                                

                        }//end if shorexSet

                }catch(Exception e){
                        throw new DocumentException(e.getMessage());
                }


regards,

Rajeev Jain

__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to