Dirk Ulrich wrote:
I want to put an image and a text into one PdfPCell of a PdfPTable.
OK, piece of cake, see attachment. > 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. Oh, you want the image to be in the middle vertically and still have some text below. That's more difficult. Can't you play with the leading? For instance: define a fixed width for the cell, based on the height of the image. Then add the image at the correct position using the leading, then add some text with a certain leading.
Using this code, the text after the image is placed on the baseline:
I don't see any padding, nor do I see setUseDescender anywhere.
I have also tryed to put image and text in a separate cell of a table of four cells and to set the rightBorderWidth of the first and the leftBorderWidth of the second cell to 0. This ends up in a ta ble with a thinner outer border for the first both cells. ???
Setting the border width to 0 doesn't mean you remove the borders. As is explained in the PDF Reference AND in 'iText in Action', a width of 0 means you want to draw the thinnest line possible (depending on the device). If you want to remove the border: use setBorder(NO_BORDER);
BTW: If I add a value to a PdfPCell and then try to ADD a further value with PdfPCell.add(...) the first value will be replaced instead of being added as expected. This method should be named setValue or put or so, shouldn't it? The add method should really add something to the already existing value of this cell. What do you think about this?
This is normal behavior. You are mixing 'text mode' with 'composite mode'. Ah, tomorrow I will be a happy man, because then I will be able to say: it's all documented in the book 'iText in Action'. The eBook version is available here: http://www.manning.com/affiliate/idevaffiliate.php?id=223_53 If I have some more time, I'll adapt my example so that it matches your requirements. br, Bruno
dirk_ulrich.pdf
Description: Adobe PDF document
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"); Paragraph p1 = new Paragraph(); p1.add(new Chunk(img, 0, 0)); p1.setLeading(img.height()); p1.setAlignment(Element.ALIGN_CENTER); Paragraph p2 = new Paragraph("This is some text that is printed using the default alignment (ALIGN_LEFT)."); PdfPTable table = new PdfPTable(1); PdfPCell cell = new PdfPCell(); cell.addElement(p1); cell.addElement(p2); cell.setPadding(3); cell.setUseAscender(true); cell.setUseDescender(true); 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(); } }
------------------------------------------------------------------------- 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