Dirk Ulrich wrote:
I want to put an image and a text into one PdfPCell of a PdfPTable.The vertical alignment of the text shall be middle to the image (which shall be placed on the left). Between the image and the following text there shall be some space.
Et voilĂ . Klaar is kees ;-) br, Bruno
package test; import java.io.FileOutputStream; import java.io.IOException; import com.lowagie.text.Chunk; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Element; import com.lowagie.text.Image; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfPCell; import com.lowagie.text.pdf.PdfPTable; import com.lowagie.text.pdf.PdfWriter; public class DirkUlrich { public static void main(String[] args) { // step 1: creation of a document-object Document document = new Document(); try { // step 2: // we create a writer PdfWriter.getInstance( // that listens to the document document, // and directs a PDF-stream to a file new FileOutputStream("dirk_ulrich.pdf")); // step 3: we open the document document.open(); // step 4: we add a table to the document Image img = Image.getInstance("fflogo.jpg"); float margin = 60; PdfPTable table = new PdfPTable(1); PdfPCell cell = new PdfPCell(); cell.setFixedHeight(img.height() + margin); Paragraph p1 = new Paragraph(); p1.add(new Chunk(img, 0, 0)); p1.setLeading(img.height() + margin / 2); cell.addElement(p1); Paragraph p2 = new Paragraph("This text is right aligned (for fun)."); p2.setLeading(20); p2.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p2); table.addCell(cell); document.add(table); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5: we close the document document.close(); } }
dirk_ulrich.pdf
Description: Adobe PDF document
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions