Hello,

i'm trying to write an application in which the content of a JTextPane (images and styled text) is being written to an pdf. When adding an image to a chunk and then to the pdf, only the lower part of the image is visible:

http://n-wt.com/1148476364453.pdf

Is there a way to set the height of the chunk to the height of the image?

Here is the code:

public void printFirstPage(Klasse k){
        try{
                Phrase ph = new Phrase();
                writer.setPageEmpty(true);
                int oldAlign=0;
                document.setMargins(50, 10, 50, 10);
                for (int i=0;i<k.getFirstPageTexte().size();i++){
                        Font rf=null;
                        TextElement te = k.getFirstPageTexte().elementAt(i);
                        if (te.io == null){
                                /*Has no Image*/
                                int style = Font.UNDEFINED;
                                if (te.bold)
                                        if (te.italic)
                                                style=Font.BOLDITALIC;
                                        else
                                                style=Font.BOLD;
                                if (te.italic)
                                        style = Font.ITALIC;
                                rf = FontFactory.getFont(te.font,te.size, 
style, te.color);
                                if (te.allginment != oldAlign){
                                        Chunk c = new Chunk(te.text,rf);
                                        ph.add(c);
                                        document.add(ph);
                                        oldAlign = te.allginment;
                                }else{
                                        Chunk p = new Chunk(te.text,rf);
                                        ph.add(p);
                                }
                        }else{
                                /*Has Image*/
Image img = Image.getInstance(((ImageIcon)te.io).getImage(),null,false);
                                img.setAlignment(Image.LEFT|Image.TEXTWRAP);
                                ph.add(new Chunk(img,0,0,true));
                        }
                }
                document.add(ph);
                document.close();
        }catch(Exception x){
                x.printStackTrace();
        }
}


Thanks in advance
Bruno


-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to