Hi,

I try to have a footer with an image inside.
I add a paragraph which contains an Image in a HeaderFooter object, and I 
invoke the Document.setFooter() method.

The result is unexpected.

What is wrong?
Thank for your help.

Here is the code sample (testFooter.java).

package test;

import java.io.FileOutputStream;
import java.io.OutputStream;

import javax.swing.ImageIcon;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.HeaderFooter;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfWriter;

public class TestFooter {
 
// The PDF Output and the Image source filenames
        public String path = "c:\\temp\\";
        public String pdfFileName = path + "testFooter.pdf";
        public String imgFileName = path + "testFooter.jpg";

        public TestFooter() {
                super();
        }
 
//The method to launch the test
        public void test(OutputStream os) {
                try {
                        Document doc = new Document(PageSize.A4);
                        PdfWriter writer = PdfWriter.getInstance(doc,os);
                        doc.setFooter(getFooter());
                        doc.open();
                        doc.add(new Phrase("This is a document with an 
unexpected image position"));
                        doc.close();
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
 
//The method which create the footer
        protected HeaderFooter getFooter() throws Exception {
                Paragraph p = new Paragraph();
                ImageIcon ii = new ImageIcon(imgFileName);
                Image i = Image.getInstance(ii.getImage(),null);
                p.add(new Chunk("Footer start"));
                p.add(i);
                p.add(new Chunk("Footer end"));
                return new HeaderFooter(p,false);
        }

The classic main method to start the test
        public static void main(String[] args) {
                try {
                        TestFooter o = new TestFooter();
                        OutputStream os = new 
FileOutputStream(o.pdfFileName);
                        o.test(os);
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
}


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to